Skip to main content
Solved

Jamf Helper Jamf Self Service Script


Forum|alt.badge.img+4

I have been trying to get a script working that will run jamf Helper and if the user agrees to the upgrade it will open Self Service at the policy and either view or install the app. So far I have the below which works.

#!/bin/zsh
### 


msg="$4 $singleApp "
singleApp="$5"
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
currentuser=$(stat -f "%Su" /dev/console)
policyid="$6"
action="$7"
timeout="$8"


    title="Application Update"

    iconLoc="/private/var/tva/casper/scripts/mickey.png"

    userResponse=`$jamfHelper -windowType utility -title "$title" -description "$msg" -icon $iconLoc -button1 "Dismiss" -button2 "Upgrade Now" -defaultButton 0 -cancelButton 1 -countdown $timeout -timeout $timeout`
#Self Service = 2
#OK = 0





        if [[ $userResponse = "2" ]]; then
        su "$currentuser" -c 'open "jamfselfservice://content?entity=policy&id=1234&action=view"'
            exit 0
        else
            exit 0
        fi
    fi
    exit 0

jamf recon


exit 0

But when I try to substitute the open command with the parameters it launches Self Service and takes me to a login screen.

#!/bin/zsh
### 


msg="$4 $singleApp "
singleApp="$5"
jamfHelper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
currentuser=$(stat -f "%Su" /dev/console)
policyid="$6"
action="$7"
timeout="$8"


    title="Application Update"

    iconLoc="/private/var/tva/casper/scripts/mickey.png"

    userResponse=`$jamfHelper -windowType utility -title "$title" -description "$msg" -icon $iconLoc -button1 "Dismiss" -button2 "Upgrade Now" -defaultButton 0 -cancelButton 1 -countdown $timeout -timeout $timeout`
#Self Service = 2
#OK = 0





        if [[ $userResponse = "2" ]]; then

        su "$currentuser" -c 'open "jamfselfservice://content?entity=policy&id=$6&action=$7"'
            exit 0
        else
            exit 0
        fi
    fi
    exit 0

jamf recon


exit 0

I found this online but I don't know how to make it work.

When using variables in shell, you can only use doubles quotes, not single quotes : the variables inside single quotes are not expanded.

When I do this I see the following

Script exit code: 2
Script result: /Library/Application Support/JAMF/tmp/JamfHelper_Sierra_Upgrade:29: parse error near `&'

Error running script: return code was 2.
Checking for patches...

Best answer by mm2270

Hey @MouseTester I did some testing with this, and was also running into strange issues where the variables wouldn't get passed down to the url correctly among other things. I'm still working on it, but in the interim, I found this is most likely an issue with zsh, since I can get this to work reliably with other shells like #!/bin/sh and #!/bin/bash. Here's a script I put together somewhat similar to what you posted that works for me. This works whether I call it using a custom trigger from Terminal or if I allow it to fire off on the check-in trigger. See if this works for you. If it does, I imagine you could use this for now since #!/bin/sh shouldn't be going anywhere in the near future.

If I manage to get it working more reliably with zsh I'll post back with my results.

#!/bin/sh

jamf_helper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

app="$4"
title="${app} Upgrade"
msg="There is an upgrade available for ${app}. Click "Install" to open the Self Service policy to view the upgrade."
icon="/System/Library/PreferencePanes/SoftwareUpdate.prefPane/Contents/Resources/SoftwareUpdate.icns"

current_user=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/&&!/loginwindow/{print $3}')
current_uid=$(id -u "$current_user")

policy_id="$5"
action="$6"

url="jamfselfservice://content?entity=policy&id=$policy_id&action=$action"

user_response=$("$jamf_helper" 
    -windowType utility 
    -title "$title" 
    -description "$msg" 
    -icon "$icon" 
    -button1 "Install" 
    -button2 "Now Now" 
    -defaultButton 1)

if [ "$user_response" == "0" ]; then
    /bin/launchctl asuser $current_uid open $url
else
    exit 0
fi

I only tested this so far in Catalina (10.15.7). I can't yet vouch for it on Big Sur, but that will be my next set of tests.

View original

7 replies

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • November 17, 2020

You should probably be using the actual variables of policyid and action inside the url string and not the parameters of $6 and $7 for one thing. You assign $6 and $7 to policyid and action respectively up top, but then you don't use them. While it's not absolutely necessary to use them, there's not much point in assigning them if you don't plan to use them later.

Also when using them I would enclose them in curly braces to be sure they don't get confused with other parts of the URL, like so:

'open "jamfselfservice://content?entity=policy&id=${policyid}&action=${action}"'

Try that and see if it works better.


Forum|alt.badge.img+4
  • Author
  • New Contributor
  • 2 replies
  • November 17, 2020

Hey mm2270,

You are correct. I used $6 instead of the parameters. I made that mistake when trying to reproduce the errors. Thank you for the suggestion. When I replace the line I see the below:

Script exit code: 0
Script result: policyid: Undefined variable.

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • November 18, 2020

Hey @MouseTester I did some testing with this, and was also running into strange issues where the variables wouldn't get passed down to the url correctly among other things. I'm still working on it, but in the interim, I found this is most likely an issue with zsh, since I can get this to work reliably with other shells like #!/bin/sh and #!/bin/bash. Here's a script I put together somewhat similar to what you posted that works for me. This works whether I call it using a custom trigger from Terminal or if I allow it to fire off on the check-in trigger. See if this works for you. If it does, I imagine you could use this for now since #!/bin/sh shouldn't be going anywhere in the near future.

If I manage to get it working more reliably with zsh I'll post back with my results.

#!/bin/sh

jamf_helper="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"

app="$4"
title="${app} Upgrade"
msg="There is an upgrade available for ${app}. Click "Install" to open the Self Service policy to view the upgrade."
icon="/System/Library/PreferencePanes/SoftwareUpdate.prefPane/Contents/Resources/SoftwareUpdate.icns"

current_user=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/&&!/loginwindow/{print $3}')
current_uid=$(id -u "$current_user")

policy_id="$5"
action="$6"

url="jamfselfservice://content?entity=policy&id=$policy_id&action=$action"

user_response=$("$jamf_helper" 
    -windowType utility 
    -title "$title" 
    -description "$msg" 
    -icon "$icon" 
    -button1 "Install" 
    -button2 "Now Now" 
    -defaultButton 1)

if [ "$user_response" == "0" ]; then
    /bin/launchctl asuser $current_uid open $url
else
    exit 0
fi

I only tested this so far in Catalina (10.15.7). I can't yet vouch for it on Big Sur, but that will be my next set of tests.


Forum|alt.badge.img+4
  • Author
  • New Contributor
  • 2 replies
  • November 18, 2020

Thank you mm2270,

Works great! I made a few changes to fit our environment but iot now does what I hoped for.


Forum|alt.badge.img+1
  • New Contributor
  • 6 replies
  • May 7, 2021

Just in case anyone uses the above script (works great by the way!) Make sure to fix the text for button2 at the bottom of the script. I just deployed this to a few hundred users got jokes like "If I click Now Now will it run faster?" lol. It should say "Not Now" instead of "Now Now" or in my case, I changed it to "Defer" :)


dvasquez
Forum|alt.badge.img+16
  • Valued Contributor
  • 318 replies
  • February 25, 2023
sschramm wrote:

Just in case anyone uses the above script (works great by the way!) Make sure to fix the text for button2 at the bottom of the script. I just deployed this to a few hundred users got jokes like "If I click Now Now will it run faster?" lol. It should say "Not Now" instead of "Now Now" or in my case, I changed it to "Defer" :)


I keep getting this when I test-run the script:

line 26: -windowType: command not found
.sh: line 27: -title: command not found
.sh: line 28: -description: command not found
.sh: line 29: -icon: command not found
.sh: line 30: -button1: command not found
.sh: line 31: -button2: command not found
.sh: line 32: -defaultButton: command not found

I have tried with single quotes and double. around the array. 

user_response=$("$jamf_helper" 
    -windowType utility 
    -title "$title" 
    -description "$msg" 
    -icon "$icon" 
    -button1 "Install" 
    -button2 "Now Now" 
    -defaultButton 1)

dvasquez
Forum|alt.badge.img+16
  • Valued Contributor
  • 318 replies
  • February 27, 2023
dvasquez wrote:

I keep getting this when I test-run the script:

line 26: -windowType: command not found
.sh: line 27: -title: command not found
.sh: line 28: -description: command not found
.sh: line 29: -icon: command not found
.sh: line 30: -button1: command not found
.sh: line 31: -button2: command not found
.sh: line 32: -defaultButton: command not found

I have tried with single quotes and double. around the array. 

user_response=$("$jamf_helper" 
    -windowType utility 
    -title "$title" 
    -description "$msg" 
    -icon "$icon" 
    -button1 "Install" 
    -button2 "Now Now" 
    -defaultButton 1)

Never mind but thank you very much for your help. I was able to leverage another process that worked much cleaner.  Still, thank you for all the work on this. 

 


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