reddit / emacs

In this script to run emacsclient, what is osascript for?

[deleted] · 2022-11-09 16:04
[deleted]
anaumann · 2022-11-09 16:26
You're quite right in several assumptions.. concatenating commands with `&&` will only execute subsequent commands if the command to the left executed successfully. If the `which osascript` failed, it wouldn't run the Applescript snippet. Applescript's `activate` command however does more than just starting emacs.. it will either start it or bring back up from the dock when it's minimized. So in a way, it's doing something similar to the `-a ""` option of emacsclient that will either start a new emacs instance or attach to an already running instance. I've only had to use a Mac for a couple of months at the end of my last job and I never really got emacsclient to run as smoothly as it does on Linux(since installing it via homebrew made it drop out of much of Apple's security system).. So basically, I just kept an open emacs window around for most of the day and learned to do more things in emacs than before :D Using Applescript for the "Launch or show" action of emacsclient is something that I didn't think of, but it's not the worst of ideas.. Not guarding the emacsclient command with a `which` will allow people to use the script even if it's not running on MacOS(like running a background emacs server via systemd on Linux), but they prefer to use the same way of editing a file across different machines and they don't need to check for the availability of emacsclient.