
The login-hook script runs synchronously before other login actions, and should therefore be kept short.
Note that there's also a log-OUT hook, LogoutHook, which provides run-at-logout functionality - unlike the other approaches. The script will run as the root user, so exercise due caution.Īmong the methods listed here, this is the only way to run a script as root. Sudo defaults write LoginHook /Users/Shared/Test.sh Place your script, e.g., Test.sh, in a shared location - e.g., /Users/Shared - and make sure it is executable ( chmod +x /Users/Shared/Test.sh). If you have admin privileges, this is the easiest method, but it is DEPRECATED, for a variety of reasons (security, limited to a single, shared script, synchronous execution) Apple especially cautions against use of this mechanism as part of a software product. is the current user's home directory.Ĭom.apple.loginwindowlogin hook : $PATH is fixed to /usr/bin:/bin:/usr/sbin:/sbin, which notably does NOT include /usr/local/bin. The embedded script runs with the default "C" locale.
Save the *.app bundle and add it to the Login Items list in System Preferences > User & Groups > Login Items.
Add a Run Shell Script action, which adds an embedded bash script, and either paste your script code there or add a command that invokes an existing script from there. If you want to run another shell script visibly, simply use open /path/to/your-script, which will open it in Terminal.app however, the Terminal window will automatically close when your script terminates. There is no guarantee that any such application will be frontmost, so it may be obscured by other windows opened during login. The scripts themselves will run invisibly, but - with the exception of the login-hook method - you can open applications visibly from them things to note: effective for ALL users (" ") i.e., the installation takes effect for ALL users scripts are typically stored in a shared location and root (administrative) privileges ARE required for installation. specific to a given user (" ") i.e., the installation must be performed for each user, if desired scripts are typically stored in a user-specific location, and root (administrative) privileges are NOT required for installation. Note: The methods are annotated with respect to whether they are:
Ivan Kovacevic's pointers, especially the link, are helpful since at least OS X 10.9.2, your options for creating run-at-login scripts are: