About a year ago I posted an Emacs launching script which would, if Emacs were already running, use emacsclient to open a file and AppleScript to bring Emacs to the front. It works well and I use it every day, but the AppleScript activating part is very slow. I usually end up just clicking on Emacs' dock icon instead of waiting for it to finish.
After a bit of hacking, instead of:
osascript -e 'tell application "Emacs" to activate'
I now use:
appswitch -i com.gnu.emacs
The speed difference is significant:
% time osascript -e 'tell application "Emacs" to activate'
osascript -e 'tell application "Emacs" to activate' 2.42s user 1.25s system 62% cpu 5.864 total
% time appswitch -i com.gnu.emacs
appswitch -i com.gnu.emacs 0.01s user 0.07s system 13% cpu 0.602 total
% time appswitch -a Emacs
appswitch -a Emacs 0.00s user 0.05s system 29% cpu 0.169 total
The -i flag is slowest because it needs to construct a CFBundle; fast matching occurs on application name, path, process ID and creator. (Process ID matching would be fastest if I directly converted to a process serial number, but I don't do that.)
If you've used my launch tool, you'll find appswitch very similar—I borrowed quite a bit from launch to write it. I hope it will be similarly useful “glue” for others.
Download appswitch here.