How to use JamfHelper to create a notification and button that will open a self service policy?

PEBKAC
New Contributor

Here is the script I am currently using. I would like to convert it to Jamfhelper so I can use a logo which using the below console output workflow does not allow.  Does anyone know how to convert this to use jamfhelper?

 

#!/bin/bash

user=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
#get User ID
uid=$(id -u "$user")


#Display a message to the user and if they click OK it will open the Self Service Policy

#Message I want to Display- Make labels in Jamf
messageToDisplay="$4"
policyIDtoExecute="$5"
policyAction="$6"

#This will use a here doc MUST PUT ENTER/RETURN AFTER EOF
#EOF is an example. You can use ANY word.. IE SHUTTLECOCK
buttonClicked=$(launchctl asuser "$uid" /usr/bin/osascript << EOF
button returned of (display dialog "$messageToDisplay" buttons {"Delay Upgrade", "Upgrade"} default button 1)
EOF
)

echo "$buttonClicked"
# For paramter six we are going to view or execute
if [[ "$buttonClicked" == "Upgrade" ]];then
/bin/launchctl asuser "$uid" /usr/bin/open "jamfselfservice://content?entity=policy&id=$policyIDtoExecute&action=$policyAction"
fi

9 REPLIES 9

mm2270
Legendary Contributor III

Try this:

 

#!/bin/bash

user=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
#get User ID
uid=$(id -u "$user")


#Display a message to the user and if they click OK it will open the Self Service Policy

#Message I want to Display- Make labels in Jamf
messageToDisplay="$4"
policyIDtoExecute="$5"
policyAction="$6"

buttonClicked=$("/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" \
	-windowType utility \
	-title "" \
	-description "$messageToDisplay" \
	-button1 "Delay Upgrade" \
	-button2 "Upgrade" \
	-defaultButton 1 \
	-icon "/path/to/icon.png")

echo "$buttonClicked"
# For paramter six we are going to view or execute
if [[ "$buttonClicked" == "2" ]];then
	/bin/launchctl asuser "$uid" /usr/bin/open "jamfselfservice://content?entity=policy&id=$policyIDtoExecute&action=$policyAction"
fi

 

You might need to experiment with this, because jamfHelper has a size limitation for button length. The "Delay Upgrade" button label looks like it gets cut off a little in my quick tests.

PEBKAC
New Contributor

Thanks so much! This does work, but for whatever reason it fails if I try to run it as standard user (without admin privelages) the message will appear but when I click the button to launch self service I get a message that pops up saying Self Service Crashed with an error. (works flawlessly on admin machines however.) Here is the full error output:

 

 

 

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process: Self Service [3404]
Path: /Applications/Self Service.app/Contents/MacOS/Self Service
Identifier: com.jamfsoftware.selfservice.mac
Version: 10.35.0 (10.35.0-t1640197529)
Code Type: X86-64 (Native)
Parent Process: launchd [1]
User ID: 504

Date/Time: 2022-02-15 10:40:40.4429 -0600
OS Version: macOS 12.2 (21D49)
Report Version: 12
Bridge OS Version: 3.0 (14Y910)
Anonymous UUID: FB77831B-213E-C3B4-30C1-68445D07F721

Sleep/Wake UUID: F4CFD6F8-C8EC-4D2C-9E24-0C32194F5783

Time Awake Since Boot: 660 seconds
Time Since Wake: 83 seconds

System Integrity Protection: enabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x7ff81c79b112 __pthread_kill + 10
1 libsystem_pthread.dylib 0x7ff81c7d1214 pthread_kill + 263
2 libsystem_c.dylib 0x7ff81c71dd10 abort + 123
3 Sentry 0x10ee4219b -[SentryCrashExceptionApplication _crashOnException:] + 58
4 AppKit 0x7ff81f643e0f -[NSApplication reportException:] + 731
5 Sentry 0x10ee42134 -[SentryCrashExceptionApplication reportException:] + 371
6 AppKit 0x7ff81f2b75e1 -[NSApplication finishLaunching] + 2920
7 AppKit 0x7ff81f2b67c9 -[NSApplication run] + 250
8 AppKit 0x7ff81f28a7b7 NSApplicationMain + 816
9 Self Service 0x10e27bea9 0x10e276000 + 24233
10 dyld 0x10ebbf4fe start + 462

Thread 1:
0 libsystem_pthread.dylib 0x7ff81c7ccfec start_wqthread + 0

Thread 2:
0 libsystem_pthread.dylib 0x7ff81c7ccfec start_wqthread + 0

Thread 3:
0 libsystem_pthread.dylib 0x7ff81c7ccfec start_wqthread + 0

Thread 4:
0 libsystem_pthread.dylib 0x7ff81c7ccfec start_wqthread + 0


Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x000000010ec3a600 rcx: 0x00007ff7b1c893f8 rdx: 0x0000000000000000
rdi: 0x0000000000000103 rsi: 0x0000000000000006 rbp: 0x00007ff7b1c89420 rsp: 0x00007ff7b1c893f8
r8: 0x0000000000000010 r9: 0x00007ff8371bbb20 r10: 0x0000000000000000 r11: 0x0000000000000246
r12: 0x0000000000000103 r13: 0x000000010ee76d86 r14: 0x0000000000000006 r15: 0x0000000000000016
rip: 0x00007ff81c79b112 rfl: 0x0000000000000246 cr2: 0x000000010ee6c000

Logical CPU: 0
Error Code: 0x02000148
Trap Number: 133


Binary Images:
0x7ff81c794000 - 0x7ff81c7cafff libsystem_kernel.dylib (*) <c1d58a50-5a4d-3bcb-a1fc-ec0902ce34d3> /usr/lib/system/libsystem_kernel.dylib
0x7ff81c7cb000 - 0x7ff81c7d6fff libsystem_pthread.dylib (*) <ee564342-d8f2-396d-b642-40092cf34d82> /usr/lib/system/libsystem_pthread.dylib
0x7ff81c69c000 - 0x7ff81c724fff libsystem_c.dylib (*) <4b160c81-ec52-3243-aaba-49f719bbf617> /usr/lib/system/libsystem_c.dylib
0x10ee34000 - 0x10ee83fff org.cocoapods.Sentry (5.2.2) <828ade21-507f-3677-8593-c494022c2a38> /Applications/Self Service.app/Contents/Frameworks/Sentry.framework/Versions/A/Sentry
0x7ff81f287000 - 0x7ff820118fff com.apple.AppKit (6.9) <a737ebe6-3a9c-32f3-b975-5ce0ef6313e4> /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
0x10e276000 - 0x10e419fff com.jamfsoftware.selfservice.mac (10.35.0) <cdc0d988-752d-3e30-9b07-34726244c9bf> /Applications/Self Service.app/Contents/MacOS/Self Service
0x10ebba000 - 0x10ec25fff dyld (*) <7de33963-bbc5-3996-ba6e-f1d562c17c95> /usr/lib/dyld

External Modification Summary:
Calls made by other processes targeting this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by all processes on this machine:
task_for_pid: 0
thread_create: 0
thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=1.0G resident=0K(0%) swapped_out_or_unallocated=1.0G(100%)
Writable regions: Total=613.9M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=613.9M(100%)

VIRTUAL REGION
REGION TYPE SIZE COUNT (non-coalesced)
=========== ======= =======
Accelerate framework 128K 1
Activity Tracing 256K 1
CG image 224K 6
CG raster data 32K 4
ColorSync 224K 25
CoreData 44K 1
CoreUI image data 424K 3
Foundation 16K 1
Kernel Alloc Once 8K 1
MALLOC 219.1M 50
MALLOC guard page 32K 7
MALLOC_NANO (reserved) 384.0M 1 reserved VM address space (unallocated)
STACK GUARD 56.0M 5
Stack 10.0M 5
VM_ALLOCATE 20K 5
__DATA 23.6M 424
__DATA_CONST 24.2M 264
__DATA_DIRTY 1244K 155
__FONT_DATA 4K 1
__LINKEDIT 645.9M 27
__OBJC_RO 81.8M 1
__OBJC_RW 3136K 2
__TEXT 411.0M 445
__UNICODE 588K 1
dyld private memory 1024K 1
mapped file 145.2M 25
shared memory 772K 16
=========== ======= =======
TOTAL 2.0G 1478
TOTAL, minus reserved VM space 1.6G 1478

 

-----------
Full Report
-----------

{"app_name":"Self Service","timestamp":"2022-02-15 10:40:40.00 -0600","app_version":"10.35.0","slice_uuid":"cdc0d988-752d-3e30-9b07-34726244c9bf","build_version":"10.35.0-t1640197529","platform":1,"bundleID":"com.jamfsoftware.selfservice.mac","share_with_app_devs":1,"is_first_party":0,"bug_type":"309","os_version":"macOS 12.2 (21D49)","incident_id":"BBE8798F-4924-450A-A363-08638C5D2900","name":"Self Service"}
{
"uptime" : 660,
"procLaunch" : "2022-02-15 10:40:40.1055 -0600",
"procRole" : "Foreground",
"version" : 2,
"userID" : 504,
"deployVersion" : 210,
"modelCode" : "MacBookPro14,3",
"procStartAbsTime" : 663974290828,
"coalitionID" : 708,
"osVersion" : {
"train" : "macOS 12.2",
"build" : "21D49",
"releaseType" : "User"
},
"captureTime" : "2022-02-15 10:40:40.4429 -0600",
"incident" : "BBE8798F-4924-450A-A363-08638C5D2900",
"bug_type" : "309",
"pid" : 3404,
"procExitAbsTime" : 664310938833,
"cpuType" : "X86-64",
"procName" : "Self Service",
"procPath" : "\/Applications\/Self Service.app\/Contents\/MacOS\/Self Service",
"bundleInfo" : {"CFBundleShortVersionString":"10.35.0","CFBundleVersion":"10.35.0-t1640197529","CFBundleIdentifier":"com.jamfsoftware.selfservice.mac"},
"storeInfo" : {"deviceIdentifierForVendor":"7DE2390A-F151-5CED-80A5-5F05772B64FB","thirdParty":true},
"parentProc" : "launchd",
"parentPid" : 1,
"coalitionName" : "com.jamfsoftware.selfservice.mac",
"crashReporterKey" : "FB77831B-213E-C3B4-30C1-68445D07F721",
"wakeTime" : 83,
"bridgeVersion" : {"build":"14Y910","train":"3.0"},
"sleepWakeUUID" : "F4CFD6F8-C8EC-4D2C-9E24-0C32194F5783",
"sip" : "enabled",
"isCorpse" : 1,
"exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGABRT"},
"asi" : {"libsystem_c.dylib":["abort() called"]},
"extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
"faultingThread" : 0,
"threads" : [{"triggered":true,"id":54025,"threadState":{"r13":{"value":4545015174},"rax":{"value":0},"rflags":{"value":582},"cpu":{"value":0},"r14":{"value":6},"rsi":{"value":6},"r8":{"value":16},"cr2":{"value":4544970752},"rdx":{"value":0},"r10":{"value":0},"r9":{"value":140704053181216,"objc-selector":"listeners"},"r15":{"value":22},"rbx":{"value":4542670336,"symbolLocation":0,"symbol":"_main_thread"},"trap":{"value":133},"err":{"value":33554760},"r11":{"value":582},"rip":{"value":140703606354194,"matchesCrashFrame":1},"rbp":{"value":140701816362016},"rsp":{"value":140701816361976},"r12":{"value":259},"rcx":{"value":140701816361976},"flavor":"x86_THREAD_STATE","rdi":{"value":259}},"queue":"com.apple.main-thread","frames":[{"imageOffset":28946,"symbol":"__pthread_kill","symbolLocation":10,"imageIndex":0},{"imageOffset":25108,"symbol":"pthread_kill","symbolLocation":263,"imageIndex":1},{"imageOffset":531728,"symbol":"abort","symbolLocation":123,"imageIndex":2},{"imageOffset":57755,"symbol":"-[SentryCrashExceptionApplication _crashOnException:]","symbolLocation":58,"imageIndex":3},{"imageOffset":3919375,"symbol":"-[NSApplication reportException:]","symbolLocation":731,"imageIndex":4},{"imageOffset":57652,"symbol":"-[SentryCrashExceptionApplication reportException:]","symbolLocation":371,"imageIndex":3},{"imageOffset":198113,"symbol":"-[NSApplication finishLaunching]","symbolLocation":2920,"imageIndex":4},{"imageOffset":194505,"symbol":"-[NSApplication run]","symbolLocation":250,"imageIndex":4},{"imageOffset":14263,"symbol":"NSApplicationMain","symbolLocation":816,"imageIndex":4},{"imageOffset":24233,"imageIndex":5},{"imageOffset":21758,"symbol":"start","symbolLocation":462,"imageIndex":6}]},{"id":54047,"frames":[{"imageOffset":8172,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":1}]},{"id":54048,"frames":[{"imageOffset":8172,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":1}]},{"id":54060,"frames":[{"imageOffset":8172,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":1}]},{"id":54083,"frames":[{"imageOffset":8172,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":1}]}],
"usedImages" : [
{
"source" : "P",
"arch" : "x86_64",
"base" : 140703606325248,
"size" : 225280,
"uuid" : "c1d58a50-5a4d-3bcb-a1fc-ec0902ce34d3",
"path" : "\/usr\/lib\/system\/libsystem_kernel.dylib",
"name" : "libsystem_kernel.dylib"
},
{
"source" : "P",
"arch" : "x86_64",
"base" : 140703606550528,
"size" : 49152,
"uuid" : "ee564342-d8f2-396d-b642-40092cf34d82",
"path" : "\/usr\/lib\/system\/libsystem_pthread.dylib",
"name" : "libsystem_pthread.dylib"
},
{
"source" : "P",
"arch" : "x86_64",
"base" : 140703605309440,
"size" : 561152,
"uuid" : "4b160c81-ec52-3243-aaba-49f719bbf617",
"path" : "\/usr\/lib\/system\/libsystem_c.dylib",
"name" : "libsystem_c.dylib"
},
{
"source" : "P",
"arch" : "x86_64",
"base" : 4544741376,
"CFBundleShortVersionString" : "5.2.2",
"CFBundleIdentifier" : "org.cocoapods.Sentry",
"size" : 327680,
"uuid" : "828ade21-507f-3677-8593-c494022c2a38",
"path" : "\/Applications\/Self Service.app\/Contents\/Frameworks\/Sentry.framework\/Versions\/A\/Sentry",
"name" : "Sentry",
"CFBundleVersion" : "1"
},
{
"source" : "P",
"arch" : "x86_64",
"base" : 140703651360768,
"CFBundleShortVersionString" : "6.9",
"CFBundleIdentifier" : "com.apple.AppKit",
"size" : 15278080,
"uuid" : "a737ebe6-3a9c-32f3-b975-5ce0ef6313e4",
"path" : "\/System\/Library\/Frameworks\/AppKit.framework\/Versions\/C\/AppKit",
"name" : "AppKit",
"CFBundleVersion" : "2113.30.116"
},
{
"source" : "P",
"arch" : "x86_64",
"base" : 4532428800,
"CFBundleShortVersionString" : "10.35.0",
"CFBundleIdentifier" : "com.jamfsoftware.selfservice.mac",
"size" : 1720320,
"uuid" : "cdc0d988-752d-3e30-9b07-34726244c9bf",
"path" : "\/Applications\/Self Service.app\/Contents\/MacOS\/Self Service",
"name" : "Self Service",
"CFBundleVersion" : "10.35.0-t1640197529"
},
{
"source" : "P",
"arch" : "x86_64",
"base" : 4542144512,
"size" : 442368,
"uuid" : "7de33963-bbc5-3996-ba6e-f1d562c17c95",
"path" : "\/usr\/lib\/dyld",
"name" : "dyld"
}
],
"sharedCache" : {
"base" : 140703603318784,
"size" : 15216836608,
"uuid" : "985a74d2-8e9c-3f64-9035-a786b4845287"
},
"vmSummary" : "ReadOnly portion of Libraries: Total=1.0G resident=0K(0%) swapped_out_or_unallocated=1.0G(100%)\nWritable regions: Total=613.9M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=613.9M(100%)\n\n VIRTUAL REGION \nREGION TYPE SIZE COUNT (non-coalesced) \n=========== ======= ======= \nAccelerate framework 128K 1 \nActivity Tracing 256K 1 \nCG image 224K 6 \nCG raster data 32K 4 \nColorSync 224K 25 \nCoreData 44K 1 \nCoreUI image data 424K 3 \nFoundation 16K 1 \nKernel Alloc Once 8K 1 \nMALLOC 219.1M 50 \nMALLOC guard page 32K 7 \nMALLOC_NANO (reserved) 384.0M 1 reserved VM address space (unallocated)\nSTACK GUARD 56.0M 5 \nStack 10.0M 5 \nVM_ALLOCATE 20K 5 \n__DATA 23.6M 424 \n__DATA_CONST 24.2M 264 \n__DATA_DIRTY 1244K 155 \n__FONT_DATA 4K 1 \n__LINKEDIT 645.9M 27 \n__OBJC_RO 81.8M 1 \n__OBJC_RW 3136K 2 \n__TEXT 411.0M 445 \n__UNICODE 588K 1 \ndyld private memory 1024K 1 \nmapped file 145.2M 25 \nshared memory 772K 16 \n=========== ======= ======= \nTOTAL 2.0G 1478 \nTOTAL, minus reserved VM space 1.6G 1478 \n",
"legacyInfo" : {
"threadTriggered" : {
"queue" : "com.apple.main-thread"
}
},
"trialInfo" : {
"rollouts" : [
{
"rolloutId" : "5ffde50ce2aacd000d47a95f",
"factorPackIds" : {

},
"deploymentId" : 240000102
},
{
"rolloutId" : "5fc94383418129005b4e9ae0",
"factorPackIds" : {

},
"deploymentId" : 240000225
},
{
"rolloutId" : "601d9415f79519000ccd4b69",
"factorPackIds" : {
"SIRI_TEXT_TO_SPEECH" : "61f0405329647d394933a4c4"
},
"deploymentId" : 240000378
},
{
"rolloutId" : "602ad4dac86151000cf27e46",
"factorPackIds" : {
"SIRI_DICTATION_ASSETS" : "6193d03f2171a2330e561dfc"
},
"deploymentId" : 240000298
},
{
"rolloutId" : "60da5e84ab0ca017dace9abf",
"factorPackIds" : {

},
"deploymentId" : 240000008
},
{
"rolloutId" : "607844aa04477260f58a8077",
"factorPackIds" : {
"SIRI_MORPHUN_ASSETS" : "6103050cbfe6dc472e1c982a"
},
"deploymentId" : 240000066
}
],
"experiments" : [
{
"treatmentId" : "91be9c58-1d64-484d-b8d5-0bf7a6bb641c",
"experimentId" : "60c785f07aa5af21f0101872",
"deploymentId" : 400000012
}
]
}
}

Model: MacBookPro14,3, BootROM 447.80.3.0.0, 4 processors, Quad-Core Intel Core i7, 3.1 GHz, 16 GB, SMC 2.45f5
Graphics: Intel HD Graphics 630, Intel HD Graphics 630, Built-In
Display: Color LCD, 2880 x 1800 Retina, Main, MirrorOff, Online
Graphics: Radeon Pro 560, Radeon Pro 560, PCIe, 4 GB
Memory Module: BANK 0/DIMM0, 8 GB, LPDDR3, 2133 MHz, 0x802C, 0x4D5435324C31473332443450472D30393320
Memory Module: BANK 1/DIMM0, 8 GB, LPDDR3, 2133 MHz, 0x802C, 0x4D5435324C31473332443450472D30393320
AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x173), Broadcom BCM43xx 1.0 (7.77.111.1 AirPortDriverBrcmNIC-1710.3)
AirPort:
Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB30Bus
USB Device: Apple T1 Controller
Thunderbolt Bus: MacBook Pro, Apple Inc., 41.5
Thunderbolt Bus: MacBook Pro, Apple Inc., 41.5

 

mm2270
Legendary Contributor III

@PEBKAC I'm not exactly sure what you mean when you say you're running it as a standard user. You mean the script itself, or the policy is running while a standard user is logged in? You can't really run the script itself as a standard user, in case that's what you were attempting. The launchctl asuser syntax requires that to be running as an admin or root preferably, so it can run the command that follows as the user account you specify.

If you're seeing those errors when a standard user is logged in and the policy runs, then there's something wrong with the script syntax. I did notice you are using this:

/bin/launchctl asuser "$uid" /usr/bin/open "jamfselfservice://content?entity=policy&id=$policyIDtoExecute&action=$policyAction"

I've often found this to be more reliable:

/bin/launchctl asuser "$uid" sudo -iu "user" /usr/bin/open "jamfselfservice://content?entity=policy&id=$policyIDtoExecute&action=$policyAction"

 Try adding that if those errors are coming up when the script runs from a regular Jamf Pro policy.

sdagley
Esteemed Contributor II

@mm2270 Have you seen any issue with Self Service crashing when being called from a script triggered via a LaunchDaemon?

I'm seeing Self Service 10.40.1 on macOS 12.5.1 crash due to a SIGABRT when launched that way. Running the same script from Terminal via sudo does successfully launch Self Service. The script _should_ be doing all the needed things to open Self Service in the user context: 

/bin/launchctl asuser "$currentUserID" sudo -u "$currentUser" /usr/bin/open "jamfselfservice://..."

 

dvasquez
Valued Contributor

I have customized this script and it does work, many thanks! But after clicking to upgrade self-service opens and then prompts for login. How do I get the policy to be front and center for an end-user to execute without logging into the app?

Thank you.

dvasquez
Valued Contributor

The script above worked very well. I made a few changes as I could not get the variables to stick to the correct information to be used. But actually putting in the script "policy ID" and "action" worked very well. 

I was also getting the following after the helper prompt was clicked to action. But it had more to do with the self-service... string was wrong (for me). I copied it right from the console and edited and it worked nicely.

Screenshot 2023-02-27 at 1.11.59 PM.png

dvasquez
Valued Contributor

Screenshot 2023-02-27 at 4.08.04 PM.png

 This is what I put together.  Thanks again!

junjishimazaki
Valued Contributor

That was a really great guide. Thank you for sharing!