4873117d302066e98e36a9165c4fc8926390c31f
[dotfiles.git] / scripts / emacs_toggle.applescript
1
2 ## this scirpt works together with Quicksilver
3 ## copy/link this file to ~/Library/Application Support/Quicksilver/Action
4 ## and set a toggle event on Quicksilver preference
5 #tell application "System Events"
6 #    tell application process "Emacs"
7 #        if visible then
8 #            set visible to false
9 #        else
10 #            set visible to true
11 #            tell application "Emacs" to activate
12 #        end if
13 #    end tell
14 #end tell
15 #
16 ## http://brettterpstra.com/2011/01/22/quick-tip-applescript-application-toggle/ 
17 set appName to "Emacs"
18 set startIt to false
19 tell application "System Events"
20     if not (exists process appName) then
21         set startIt to true
22     else if frontmost of process appName then
23         set visible of process appName to false
24     else
25         set frontmost of process appName to true
26     end if
27 end tell
28 if startIt then
29     tell application appName to activate
30 end if
31