How to auto run an application on login?

JamfUser01
New Contributor II
I've got an application installed on a number of mac devices, I'm looking to have this run when a user logs.  How can I achieve this?
- The application is pushed through a Jamf policy.
- The devices are shared and logged in by many people.
- The application was composed and packaged in house.
4 REPLIES 4

jamf-42
Valued Contributor II

login policy with File and Processes 

open /Applications/APPNAME.APP

 

AJPinto
Honored Contributor III

I would suggest writing a launch agent/daemon. Basically, it's a script that runs at login to do whatever you tell it to do, including opening an application if that is what you want. If you look in /Library/LaunchDaemons you will see there are probably several on your devices already and can give you an example of what it needs to look like.

 

Once you have the launch daemon, just package and deploy.

 

Creating Launch Daemons and Agents (apple.com)

mschlosser
Contributor II

Good question, both of the above solutions work, i'd say the launch agent / daemon is a bit more durable and harder to bypass if that matters to you. when i have to make something happen on every login, i use the following script ot generate the launch agent with whatever i'd like to do, works well. Often used to mount a share, run an app, can do almost anything in user content too.

 

#!/bin/bash

# launchDaemon and Agent creator
# feed it with;
# launcher type =  Daemon or Agent
# launchItem = path to the app being launched, the full path to the executable
# launcherPlistName = unique bit of the plist name. it will be com.mycorp.{unique bit}.plist
# isScriptIn = is this a script yes or no. defines which plist will be used
#1) $4 launcher type = Daemon or Agent
#2) $5 launchItem = path to the app being launched, the full path to the executable or script
#3) $6 launcherPlistName = unique bit of the plist name. it will be com.mycorp.{unique bit}.plist
#4) $7 isScriptIn = is this a script yes or no. defines which plist type will be used

launcherTypeIn="Agent"
launchItem="/path/to/iten"
launcherPlistName="<namegoeshere>"
isScriptIn="yes"
# set input strings to lower to avoid case failure
launcherType=$(echo $launcherTypeIn | tr '[:upper:]' '[:lower:]')
isScript=$(echo $isScriptIn | tr '[:upper:]' '[:lower:]')
#echo "$launchItem"

# 
case "$launcherType" in
	
	"daemon" )
	#echo "**** Daemon ****"
	launchFolder="LaunchDaemons"
	;;

	"agent" )
	#echo "**** Agent ****"
	launchFolder="LaunchAgents"
	;;

	*)
		echo "**** no launcher type selected. Exiting *****"
		exit 1
	;;
esac

case "$isScript"  in

	"no" )

cat << EOF > /Library/${launchFolder}/com.mycorp.${launcherPlistName}.plist
<?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.mycorp.${launcherPlistName}</string>
    <key>ProgramArguments</key>
    <array>
        <string>${launchItem}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
EOF

	;;

	"yes" )

cat << EOF > /Library/${launchFolder}/com.mycorp.${launcherPlistName}.plist
<?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.mycorp.${launcherPlistName}</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>${launchItem}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
EOF

	;;

	*)
		echo "**** no type selected. Exiting *****"
		exit 1
	;;
esac

/usr/sbin/chown root:wheel /Library/${launchFolder}/com.mycorp.${launcherPlistName}.plist
/bin/chmod 644 /Library/${launchFolder}/com.mycorp.${launcherPlistName}.plist

JamfUser01
New Contributor II

I've come across a policy which seems to install a .plist into launch agent, this policy was setup by the previous employee but I can't figure out where this .plist is coming from. I've had a look under the policy and there's no indication but when I install a policy on a device it also adds the .plist.  Where else could they possible have set this up?