Launch apps automatically on logging in to MacSolved

Participant
Discussion
3 years ago

Hey guys!

We have a requirement to automatically launch these apps – Notes, Slack and Safari – every time the user’s Mac starts up. I know about the ‘Login Items’ setting in System Preferences but what I’m looking for is a remote way to do this, such as pushing a configuration profile or executing a shell script.

Appreciate any help. Thanks.

Replies (6)

Marked SolutionPending Review
Participant
3 years ago
Marked SolutionPending Review

You can create a LaunchAgent in /Library/LaunchAgents folder which will execute whenever a user logs in to the Mac.

A sample LaunchAgent plist file looks like this:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>Label</key>
<string>com.appname.plist</string>
<key>Program</key>
<string>/Applications/appname.app/</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

You can execute a script which automates the whole process. Checkout this post which I found online:

https://montysmacmusings.wordpress.com/2018/01/06/a-reusable-launchdemon-or-agent-creator-script/

Marked SolutionPending Review
Participant
3 years ago
Marked SolutionPending Review

Here’s something that I put together for launching the Messages application on our employee devices on system startup:

#!/bin/bash

touch ‘/Library/LaunchAgents/com.Messages.plist’

cat > /Library/LaunchAgents/com.Messages.plist <<EOF

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.Messages.plist</string>
<key>Program</key>
<string>/System/Applications/Messages.app/Contents/MacOS/Messages</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Feel free to use the above script. You’d need to replace the application executable path to the required values for the key, depending on the application you need to launch. Keep alive – ‘false’ will kill off the app once quit.

Marked SolutionPending Review
Participant
3 years ago
Marked SolutionPending Review

Hey @_patricia_. Thanks for sharing the script! We’ve got a little hiccup though. It worked flawlessly for the ‘Notes’ app plist file but the Safari and Slack plist files doesn’t seem to work.

Here’s a preview of the script I used for creating the Safari.plist:

#!/bin/bash

touch ‘/Library/LaunchAgents/com.Safari.plist’

cat > /Library/LaunchAgents/com.Safari.plist <<EOF

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>

<plist version=”1.0″>
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.Safari.plist</string>
<key>Program</key>
<string>/System/Applications/Safari.app/Contents/MacOS/Messages</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

Not really sure what’s wrong but I’m guessing it has gotta do something with the application path.

Marked SolutionPending Review
Participant
2 years ago
Marked SolutionPending Review

Yes, you might be right. You need to specify the absolute path to the application executable. Go to Finder > Applications and then right-click the app and choose ‘View Package Contents’. This will display all the supporting files of the application. You can find the executable binary at Contents > MacOS. Specify the path of this executable in the script and see if that works.

Marked SolutionPending Review
Participant
2 years ago
Marked SolutionPending Review

@_patricia_ Solved! Thanks man. You’re a life saver.

@Hexnode Would be nice to have this as a feature in the Hexnode portal. I see that Jamf has this.

Marked SolutionPending Review
Hexnode Expert
2 years ago
Marked SolutionPending Review

@pauel We hear you! We’ll raise this feature with our Product team on your behalf.

In the meantime, stay tuned for our latest feature updates in Release Notes.

Keep sharing your valuable suggestions.

Cheers!
Chris Wheeler
Hexnode UEM