Opening or restoring an application using AppleScript

So, you want to make some sort of keyboard shortcut to your application instead of looking for it in the dock?
The solution is quite simple, again, by using AppleScript. The following script is based on bringing the window of the application Path Finder to front, or starting the application if it is not already running. It uses an AppleScript that has been made into a service using Automator.

The script:

tellapplication “Path Finder”
        — Check if the application is running, if not then start it        
        if (countofwindows) is 0 then
        — check if the application is minimized, if so then restore the window
        ifminimizedofwindow 1 istruethen
                repeat****whileminimizedofwindow 1 istrue
                        setminimizedofwindow 1 tofalse
                — if the application is not mimimized. then bring the window to front.
        else****ifminimizedofwindow 1 isfalsethen

In order to make it into a service you can have a look here, or follow the quick reference below.

  1. Open Automator
  2. Chose to create a new Service
  3. in the left pane, select “Utilities” and then doubleclik on “Run AppleScript”. You should now have a small window on the right with the text “(* Your script goes here *)”
  4. Paste the script above
  5. Press “cmd + s” in order to save it, and give it a fancy name. I called it “Restore or minimize Path Finder” (note, this script was written to be used with Path Finder).
  6. Open “System preferences” and select “Keyboard”. Under “Keyboard shortcuts” select the “Services” option in the left pane and scroll to the bottom, your new service should now appear there.
  7. Double click the service name in order to give it a keyboard mapping.
  8. Profit o/


Note: You should be able to substitute the “Path Finder” with an application of your own choice, please remember that the “window 1” might need to be changed depending on the application and what window of it you would like to restore/bring to front.