OSX user automatically runs the corresponding shell script after logging in

original title:

Launch Shell Script Silently AT Login

In OSX I needed a shell script to execute at login. There are a few different ways to perform this so I thought it might be helpfulto document what your options are. I’ve switched over to Emacs which typically has a longer startup time than editors Such as Vim. this is the shell script we will result:

#! / bin / zshemacs –daemon

Oftentimes Emacs will stay open during an entire user session of the OS, so the sooner I can launch it the better. OSX offers a few different startup options for us. First, we have Login Items available within Account Settings of the System Preference pane. We need to rename the shell script above to end in a .command file extension to allow the Login Items to execute it. This will run at login, however we will be left with a Terminal prompt visible when the script has completed. Preferably we would execute this in the background at user login. OSX manages system and user daemons via a tool called launchd. The interface to launchd is a tool called launchctl which allows for loading and unloading daemons into launchd. XML formatted plist files are used to describe operations loaded INTO LAUNCHCTL.

Label key> Emacs-daem string> runatload key> program key> /Users/nickp/bin/scripts/launch-emacs-daemon.sh string> dict> plist>

a .command file extension. We will now use launchctl to load our plist file.launchctl loading ~ / library / launchagents / emacs-daemon.plist

To Verify That your script executed correctly lets assek launchctl to show us what is running.

Launchctl List | GREP Emacs

You Will Likey See Two Entries, Each With Three Column. Mine Looks Like this:


! With this setup, i can launch the emacsclient process Which Will attach to the daemon server and launch instantly.

Related Posts