I would like to create a launchdaemon that launch a script when finder and dock processes are existing. I don´t know if anyone has something similar running they can try and show .
the launchdaemon I can create on my own - but how to build in script that it only should run if those dock and finder process exist I struggle to find
- Home
- Community
- Get Support
- General Discussions
- Scripting help needed - launchdaemon
Scripting help needed - launchdaemon
- December 21, 2021
- 46 replies
- 37 views

- Contributor
- 194 replies
46 replies
- Honored Contributor
- 473 replies
- January 5, 2022
@Captainamerica that sounds like an ownership/permissions issue. The script works from Jamf Pro because it runs all scripts as root. I'm not sure if that's the case for packaged post-install scripts.

- Contributor
- 142 replies
- January 5, 2022
If I deploy the package through Jamf to a machine, the launchdaemon is installed and loaded and everything fine. But when same package is in pre-stage, it does not load automatically
- Honored Contributor
- 473 replies
- January 5, 2022
All I'm asking is that you try using the enrollment trigger. That's the best way to begin troubleshooting. You have to try different things to find the issue.

- Contributor
- 142 replies
- January 5, 2022
So you mean the
$jamfBinary policy -event launchWizard

- Contributor
- 142 replies
- January 5, 2022
arh ok - I understand. But this enrollment trigger in jamf is not very stable - sometimes it works other times not is that I experience. But can give it a try
- Honored Contributor
- 473 replies
- January 5, 2022
Let me know how it goes, and I'll keep helping you troubleshoot.

- Contributor
- 142 replies
- January 6, 2022
If I just add the launchdaemon script and enrollment complete trigger it works, as you asked for. I checked the file rights on the plist file to compare if there are somehow set different when it is going through pre-stage, but they are exactly the same

- Contributor
- 142 replies
- January 13, 2022
@bwoods Can you try and show you pre-stage setup in jamf.
Do you have more packages in pre-stage or just one package with both jamf connect and the launchdaemon script ?
Even Low level - can you show how the package looks like if you show a composer view of the pkg ? Something is strange that the launchdaemon also for me cannot start
- Honored Contributor
- 473 replies
- January 13, 2022
@Captainamerica I install two packages at enrollment:
1. Automated Device Enrollment Starter
a. contains a preinstall script for rosetta for M1 hardware
b. DEPNotify
c. logos for DEPNotify.
2. A Location Services Package.
a. This contains a post install script that enables location services automatically. This could have been in the ADE starter but I already had it packaged in Jamf Pro.
I install Jamf Connect with the DEPNotify GUI due to MFA policies at my organization. For now, I have my Desktop team create the accounts manually. But I have tested with Jamf Connect as well and it still works.
- Honored Contributor
- 473 replies
- January 13, 2022
Script to install Rosetta
#!/bin/bash
# Installs Rosetta as needed on Apple Silicon Macs.
exitcode=0
# Determine OS version
# Save current IFS state
OLDIFS=$IFS
IFS='.' read osvers_major osvers_minor osvers_dot_version <<< "$(/usr/bin/sw_vers -productVersion)"
# restore IFS to previous state
IFS=$OLDIFS
# Check to see if the Mac is reporting itself as running macOS 11
if [[ ${osvers_major} -ge 11 ]]; then
# Check to see if the Mac needs Rosetta installed by testing the processor
processor=$(/usr/sbin/sysctl -n machdep.cpu.brand_string | grep -o "Intel")
if [[ -n "$processor" ]]; then
echo "$processor processor installed. No need to install Rosetta."
else
# Check Rosetta LaunchDaemon. If no LaunchDaemon is found,
# perform a non-interactive install of Rosetta.
if [[ ! -f "/Library/Apple/System/Library/LaunchDaemons/com.apple.oahd.plist" ]]; then
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
if [[ $? -eq 0 ]]; then
echo "Rosetta has been successfully installed."
else
echo "Rosetta installation failed!"
exitcode=1
fi
else
echo "Rosetta is already installed. Nothing to do."
fi
fi
else
echo "Mac is running macOS $osvers_major.$osvers_minor.$osvers_dot_version."
echo "No need to install Rosetta on this version of macOS."
fi
exit $exitcode
- Honored Contributor
- 473 replies
- January 13, 2022
Script to enable location services automatically.
## configure ntp server
/bin/cat > /etc/ntp.conf << 'NEW_NTP_CONF'
server time.apple.com
NEW_NTP_CONF
## configure automatic timezone
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1
## Set date and time automatically
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeOnlyEnabled -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeZoneEnabled -bool YES
/usr/sbin/systemsetup -setusingnetworktime on
/usr/sbin/systemsetup -gettimezone
/usr/sbin/systemsetup -getnetworktimeserver
### Restart location services daemon (locationd)
/usr/bin/killall locationd
exit 0; ## Success
exit 1; ## Failure

- Contributor
- 142 replies
- January 13, 2022
Overall the issue seems to be the launchdaemon. It doesn´t start for some reason. I can read that launchdaemons can be tricky and must be very accurate or else the system will not load them.

- Contributor
- 142 replies
- January 13, 2022
so in pre-stage you do not put in the creation of launchdaemon ? that is where I have it - I first launch depnotify when user desktop is loaded
- Honored Contributor
- 473 replies
- January 13, 2022
My launchdaemon creation script and DEPNotify scripts are always in the cloud so that I can edit them without creating a new package.

- Contributor
- 142 replies
- January 13, 2022
Think we found the issue now. The jamf binary does note exist in pre-stage when the launchdaemon executes - so somehow just have to build in that the launchdaemon first launch when the jamf binary exist in the path
I would like to create a launchdaemon that launch a script when finder and dock processes are existing. I don´t know if anyone has something similar running they can try and show .
the launchdaemon I can create on my own - but how to build in script that it only should run if those dock and finder process exist I struggle to find
@Captainamerica that sounds like an ownership/permissions issue. The script works from Jamf Pro because it runs all scripts as root. I'm not sure if that's the case for packaged post-install scripts.
If I deploy the package through Jamf to a machine, the launchdaemon is installed and loaded and everything fine. But when same package is in pre-stage, it does not load automatically
All I'm asking is that you try using the enrollment trigger. That's the best way to begin troubleshooting. You have to try different things to find the issue.
So you mean the
$jamfBinary policy -event launchWizard
arh ok - I understand. But this enrollment trigger in jamf is not very stable - sometimes it works other times not is that I experience. But can give it a try
Let me know how it goes, and I'll keep helping you troubleshoot.
If I just add the launchdaemon script and enrollment complete trigger it works, as you asked for. I checked the file rights on the plist file to compare if there are somehow set different when it is going through pre-stage, but they are exactly the same
What is your prestage workflow?
@bwoods Can you try and show you pre-stage setup in jamf.
Do you have more packages in pre-stage or just one package with both jamf connect and the launchdaemon script ?
Even Low level - can you show how the package looks like if you show a composer view of the pkg ? Something is strange that the launchdaemon also for me cannot start
@Captainamerica I install two packages at enrollment:
1. Automated Device Enrollment Starter
a. contains a preinstall script for rosetta for M1 hardware
b. DEPNotify
c. logos for DEPNotify.
2. A Location Services Package.
a. This contains a post install script that enables location services automatically. This could have been in the ADE starter but I already had it packaged in Jamf Pro.
I install Jamf Connect with the DEPNotify GUI due to MFA policies at my organization. For now, I have my Desktop team create the accounts manually. But I have tested with Jamf Connect as well and it still works.
Script to install Rosetta
#!/bin/bash
# Installs Rosetta as needed on Apple Silicon Macs.
exitcode=0
# Determine OS version
# Save current IFS state
OLDIFS=$IFS
IFS='.' read osvers_major osvers_minor osvers_dot_version <<< "$(/usr/bin/sw_vers -productVersion)"
# restore IFS to previous state
IFS=$OLDIFS
# Check to see if the Mac is reporting itself as running macOS 11
if [[ ${osvers_major} -ge 11 ]]; then
# Check to see if the Mac needs Rosetta installed by testing the processor
processor=$(/usr/sbin/sysctl -n machdep.cpu.brand_string | grep -o "Intel")
if [[ -n "$processor" ]]; then
echo "$processor processor installed. No need to install Rosetta."
else
# Check Rosetta LaunchDaemon. If no LaunchDaemon is found,
# perform a non-interactive install of Rosetta.
if [[ ! -f "/Library/Apple/System/Library/LaunchDaemons/com.apple.oahd.plist" ]]; then
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
if [[ $? -eq 0 ]]; then
echo "Rosetta has been successfully installed."
else
echo "Rosetta installation failed!"
exitcode=1
fi
else
echo "Rosetta is already installed. Nothing to do."
fi
fi
else
echo "Mac is running macOS $osvers_major.$osvers_minor.$osvers_dot_version."
echo "No need to install Rosetta on this version of macOS."
fi
exit $exitcode
Script to enable location services automatically.
## configure ntp server
/bin/cat > /etc/ntp.conf << 'NEW_NTP_CONF'
server time.apple.com
NEW_NTP_CONF
## configure automatic timezone
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd LocationServicesEnabled -int 1
uuid=$(/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57)
/usr/bin/defaults write /var/db/locationd/Library/Preferences/ByHost/com.apple.locationd.$uuid LocationServicesEnabled -int 1
## Set date and time automatically
/usr/bin/defaults write /Library/Preferences/com.apple.timezone.auto Active -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeOnlyEnabled -bool YES
/usr/bin/defaults write /private/var/db/timed/Library/Preferences/com.apple.timed.plist TMAutomaticTimeZoneEnabled -bool YES
/usr/sbin/systemsetup -setusingnetworktime on
/usr/sbin/systemsetup -gettimezone
/usr/sbin/systemsetup -getnetworktimeserver
### Restart location services daemon (locationd)
/usr/bin/killall locationd
exit 0; ## Success
exit 1; ## Failure
Overall the issue seems to be the launchdaemon. It doesn´t start for some reason. I can read that launchdaemons can be tricky and must be very accurate or else the system will not load them.
so in pre-stage you do not put in the creation of launchdaemon ? that is where I have it - I first launch depnotify when user desktop is loaded
My launchdaemon creation script and DEPNotify scripts are always in the cloud so that I can edit them without creating a new package.
Think we found the issue now. The jamf binary does note exist in pre-stage when the launchdaemon executes - so somehow just have to build in that the launchdaemon first launch when the jamf binary exist in the path
Reply
Related topics
iOS 10.3.1 and Clear Passcode Commandicon
General DiscussionsEthernet Connection for iPadsicon
General DiscussionsManage ethernet adapter settings for iOS (802.1x)icon
General DiscussionsUse Apple's New Tethered Caching to Send MDM commands to IOS devices with No WIFIicon
General DiscussionsRj45 adaptor for ipadsicon
General Discussions
Most helpful members this week
- Chubs
58 likes
- tommypatzius
55 likes
- MusicCityMac
28 likes
- GregBobbett
27 likes
- ktrojano
27 likes
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
Scanning file for viruses.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
OKThis file cannot be downloaded
Sorry, our virus scanner detected that this file isn't safe to download.
OKCookie 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
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.