imporve apple script toggle application
[dotfiles.git] / scripts / emacs_toggle.applescript
1 #tell application "System Events"
2 #    tell application process "Emacs"
3 #        if visible then
4 #            set visible to false
5 #        else
6 #            set visible to true
7 #            tell application "Emacs" to activate
8 #        end if
9 #    end tell
10 #end tell
11 #
12 ## http://brettterpstra.com/2011/01/22/quick-tip-applescript-application-toggle/ 
13 set appName to "Emacs"
14 set startIt to false
15 tell application "System Events"
16     if not (exists process appName) then
17         set startIt to true
18     else if frontmost of process appName then
19         set visible of process appName to false
20     else
21         set frontmost of process appName to true
22     end if
23 end tell
24 if startIt then
25     tell application appName to activate
26 end if
27