Skip to main content
Question

Script to launch on every user login MacOS


Forum|alt.badge.img+3

I am looking ultimately to launch an application for every user that logs into a Mac. I tried running a script and the policy log shows it ran with an exit code of 0.

#!/bin/bash
open -a /Applications/myapp.app
exit 0

I can make that script on the client device and execute it and it works. Any ideas as to what I am missing?

2 replies

Forum|alt.badge.img+15
  • Esteemed Contributor
  • 719 replies
  • December 26, 2019

Jamf scripts run as root. You probably want your open command to run as the logged in user.

loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
su -l $loggedInUser -c "open /Applications/myapp.app/"

Another issue you're probably running into is that jamf login scripts are usually going to run before the user's login environment has fully loaded. Look into Launch Agents. Launch Agents load when the user environment loads.


bentoms
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • December 28, 2019

This is really something that a LaunchAgent should be used for.

LaunchAgents & LaunchDaemons are important things to learn when it comes to macOS administration.

As such, have a look at: https://www.launchd.info


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings