X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=scripts%2Femacs_toggle.applescript;h=7870b6d6e2ad1c87edde69a728cb849238e007d9;hb=13c5ade6dc04b91c00b64d4a0464d3b5def1d5b4;hp=d3bbe3b1ca541255cf0b41762912c75e4b33da2a;hpb=512b2880e283c38095954db422531ad81da4dc9e;p=dotfiles.git diff --git a/scripts/emacs_toggle.applescript b/scripts/emacs_toggle.applescript index d3bbe3b..7870b6d 100644 --- a/scripts/emacs_toggle.applescript +++ b/scripts/emacs_toggle.applescript @@ -1,10 +1,53 @@ + +## this scirpt works together with Quicksilver +## copy/link this file to ~/Library/Application Support/Quicksilver/Action +## and set a toggle event on Quicksilver preference +# +## http://brettterpstra.com/2011/01/22/quick-tip-applescript-application-toggle/ +# +# +#Version 1.0 toggle emacs front + +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 + +## version 2.0 - using emacs daemon and client +##set appName to "Emacs" +##set startIt to false +##tell application "System Events" +## try +## -- we look for <= 2 because Emacs --daemon seems to always have an entry in visibile-frame-list even if there isn't +## set frameVisible to do shell script "/usr/local/bin/emacsclient -e '(<= 2 (length (visible-frame-list)))'" +## if frameVisible is not "t" then +## -- there is a not a visible frame, launch one +## do shell script "/usr/local/bin/emacsclient -c -n" +## set startIt to true +## else if frontmost of process "Emacs" then +## set visible of process "Emacs" to false +## else +## set frontmost of process "Emacs" to true +## end if +## on error +## -- daemon is not running, start the daemon and open a frame +## do shell script "/usr/local/bin/emacs --daemon" +## do shell script "/usr/local/bin/emacsclient -c -n" +## set startIt to true +## end try +##end tell +## +##-- bring the visible frame to the front +##if startIt then +## tell application "Emacs" to activate +##end if