Login Items

dtmille2
Contributor III

What is your favorite way to add a login item to your Mac? I have an app (IP in Menubar) that I'd like to start when our Macs start up.

I see there is a configuration profile for login items, but I don't see a way to add a custom application

18 REPLIES 18

dsavageED
Contributor III

We use a script...

#!/bin/bash

#Task="add"
#App_Path="/Applications/NoMAD.app"
#Hidden="true"
Task="$4"
App_Path="$5"
Hidden="$6"
Item=`basename $App_Path`
Label=`basename $App_Path | awk -F "." '{print $1}'`
User_Name=`ls -l /dev/console | awk '{print $3}'`
App_Running=`ps -A | grep "$App_Path/Contents" | grep -v "grep"`
Existing_Items=( `/usr/bin/osascript -e 'tell application "System Events" to get the name of every login item' `)
Already_Exists=`echo ${Existing_Items[@]} | grep "$Label"`

if [ -z "$App_Path" ] || [ -z "$Task" ]; then
    echo "Required variable is undefined!"
    exit 0;
fi

if [ "$Task" == "add" ]; then
    if [ -z "$Already_Exists" ] || [ "$Already_Exists" == '' ]; then
        /usr/bin/osascript <<EOF
tell application "System Events" to make login item at end with properties {Path:"$App_Path", name:"$Item", hidden:$Hidden}
EOF
    fi
    if [ -z "${App_Running}" ] || [ "${App_Running}" == '' ]; then
       open -a "${App_Path}" > /dev/null 2>&1
    fi
fi

# The delete function

if [ "$Task" == "del" ]; then
    if ! [ -z "$Already_Exists" ] || ! [ "$Already_Exists" == '' ]; then
        /usr/bin/osascript <<EOF
tell application "System Events" to delete login item "$Item"
tell application "System Events" to delete login item "$Label"
EOF
    fi
fi

exit 0;

tcarlson
New Contributor III

You can add "Items" under "Login Items" in the Config profile. Put the path to the .app file. Works the same way. FYI

Hugonaut
Valued Contributor II

I create launchagents or daemons for everything.

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

dmillertds
Contributor

@tcarlson can you elaborate? I'm trying to do just what you mention, but after adding the path to my app and clicking Save, nothing shows up under Items. I've tried absolute and relative paths, etc. It acts like it just ignores what I've put in.

donmontalvo
Esteemed Contributor II

@Hugonaut +1

--
https://donmontalvo.com

tcarlson
New Contributor III

Under Logit items, go to "Items" instead of "apps"

Type in the application path ie : /Applications/Chess.app/

The only odd thing is that it will say "1 payload configured" but may or may not show the actual item once it is saved. But will still add item to the computer.

bruth85
New Contributor III

@tcarlson I have added an app to the login items Profile but its not actually launching. I can see it in the Login Items window for the users and if I double click on it from there it launches properly but it just won't launch at login. Have you ever seen that? I have it entered into the Items section as /Applications/Chat.app/

Update: I found that the app loads fine for local accounts but wont load for Mobile accounts.

Gascolator
New Contributor III

@bruth85 I can also confirm the same behavior for mobile accounts.

ryan_ball
Valued Contributor

LaunchAgents can easily be set up for this purpose. Shameless plug.

Gascolator
New Contributor III

@ryan.ball I graciously accept your shameless plug! Will look into this.

bruth85
New Contributor III

@Gascolator here is what I ended up doing atleast for now. Might need to change it but we will see. Working with Jamf we ended up creating a policy to trigger at Login and then within Files and Processes under the Execute a Command section entered open -a "Skype for Business" because we also wanted it to run when the user is not online we checked the Make available offline box. The other thing we had to add since Skype was trying to launch before wifi was connected was a quick script to add a wait and then set it to run Before. You may already know this but the one caveat and why we may need to change the policy is the policy has to run successfully once before the system will cache it to run offline. We have some computers who only run on wifi so if they login and are not connected to the network the policy may never actually run in order to cache it, but still working with Jamf on that part.

ryan_ball
Valued Contributor

FYI, login hooks are depreciated by Apple. Jamf policies that run at login use login hooks (as of now). launchd is the way to go.

Gascolator
New Contributor III

Went with a launch agent as @ryan.ball suggested above. Took the package it spit out and added it to the profile to install alongside Google Drive File Stream. Works great.

smcmjeff
New Contributor III

Just wanted to thank @ryan.ball for the Launchd package creator. We just replaced a Mac lab that was running Sierra. Previously, I had a configuration profile that launched our GoPrint Webclient on login. After replacing our Mac lab with new iMacs running 10.14.5, I noticed the client was not launching for users logging in with their AD accounts, however, it would launch for local accounts. I used the utility to create a package (using the existing path in plist) and scoped it to my smart group for the new iMacs. The GoPrint Webclient is now launching for users logging in with their AD accounts.

cvanderzie
New Contributor II

Late to the game here, but as of 10.43, you can add them to the Managed Login Items payload.

I just wanted to drop this in here in case someone arrived at this post as I did. 

Rokas
New Contributor III

Yes you can, but at least for me it doesn't launch app at login tried ading under items "/Applications/Google\ Chrome.app/" or "/Applications/Google\ Chrome.app" or even "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" without quotes of cource.

 

Rokas
New Contributor III

It works just yoo do not need to escape spaces like i did so "/Applications/Google Chrome.app/" works fine :) 

Thank you.