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
activate
end****if
— check if the application is minimized, if so then restore the window
ifminimizedofwindow 1 istruethen
repeat****whileminimizedofwindow 1 istrue
setminimizedofwindow 1 tofalse
end****repeat
— if the application is not mimimized. then bring the window to front.
else****ifminimizedofwindow 1 isfalsethen
activate
end****if
end****tell
In order to make it into a service you can have a look here, or follow the quick reference below.
- Open Automator
- Chose to create a new Service
- 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 *)”
- Paste the script above
- 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).
- 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.
- Double click the service name in order to give it a keyboard mapping.
- 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.