Jump to content

Workflow to focus applications

Recommended Posts

Hi, I'm trying to make a workflow that allows me to switch between my mostly used applications using hot keys.


For example, I want to use Option+Command+M to bring the "Mail" application to the front, and if the app is not running, open it.


I've created the corresponding hot keys and setup a NSAppleScript:

on alfred_script(q)  
  tell application "Mail" to activate
end alfred_script

The script works fine if the application is already running, but doesn't open the app in the opposite case.


Also, with some apps, such as MacVim, the above script creates a new window instead of focusing on the current opened window.


How should the AppleScript be formulated?

Link to comment

What you've done, theoretically, should work.


Have you tried changing the script to an osascript instead of a NSAppleScript to see if it solves the problem of non-running applications launching?


For the double launching, you could try something like:

if application "MacVim" is running then
    tell application "MacVim"
        do script ""
    end tell
    tell application "MacVim" to activate
end if

It's longer, and, again, theoretically, there should be no difference, but I've seen that it sometimes does make a difference.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...