I'm working on a script that is initiated through Self Service and Startup (ongoing). I want the script to know whether it was initiated from Self Service or if it just ran because of a restart. Right now I have the script detecting whether Self Service is running when the script starts which seems to work well, but I don't want Self Service to open up as soon as a user logs in and accidentally start the script. My question, is there an easy way for the script to know if it is being run from Self Service or not?
Additional Information:
I found that a process starts when a policy is run through Self Service called "JamfManagementService", but if I run
pgrep "JamfManagementService"
inside of the script, it doesn't find anything. If I run this same script through Terminal while a policy is running through Self Service it finds it every time. I'm not sure why this process can't be found when run from inside the policy, I think this would be the best way to resolve this issue if I could get it to work, but maybe there is a better solution that I don't know about.
If it helps, I can explain the purpose of the full script and how it works, but it is a bit lengthy.
What I currently have:
# If any user is logged in and Self Service is running, then...
if [ "$3" != "" ] && pgrep "Self Service" >/dev/null 2>&1; then
echo "This script was run through Self Service"
else
echo "This script was run through Jamf trigger event"
fi
What I would like to have:
# If the JamfManagementService process is running, then...
if pgrep "JamfManagementService" >/dev/null 2>&1; then
echo "This script was run through Self Service"
else
echo "This script was run through Jamf trigger event"
fi