From 5df35baa55cdad0cb6b0fc70fb2ff512bc2bfe9c Mon Sep 17 00:00:00 2001 From: Peng Li Date: Fri, 4 Sep 2015 12:16:31 +0800 Subject: [PATCH] imporve apple script toggle application --- scripts/emacs_toggle.applescript | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/scripts/emacs_toggle.applescript b/scripts/emacs_toggle.applescript index d3bbe3b..f034a4e 100644 --- a/scripts/emacs_toggle.applescript +++ b/scripts/emacs_toggle.applescript @@ -1,10 +1,27 @@ +#tell application "System Events" +# tell application process "Emacs" +# if visible then +# set visible to false +# else +# set visible to true +# tell application "Emacs" to activate +# end if +# end tell +#end tell +# +## http://brettterpstra.com/2011/01/22/quick-tip-applescript-application-toggle/ +set appName to "Emacs" +set startIt to false tell application "System Events" - tell application process "Emacs" - if visible then - set visible to false - else - set visible to true - tell application "Emacs" to activate - end if - end tell + if not (exists process appName) then + set startIt to true + else if frontmost of process appName then + set visible of process appName to false + else + set frontmost of process appName to true + end if end tell +if startIt then + tell application appName to activate +end if + -- 2.11.0