Posted on 09-19-2017 04:13 AM
Hi All,
I am having a strange issue whilst deploying an applescript via self-service, it's written to rename the machine using the jamf helper based on the region the user selects via the UI. If i set the policy scope to ongoing the script re-runs immediately after exiting and loops forever, if i set it to once per computer the script kills after it has run once but i can see the jamf agent checking for the policy...all the time.. (screenshot attached).
Any ideas? The applescript is also below for any scripting gurus.
#!/bin/sh
#!/usr/bin/osascript
set Options to {"UK", "Ireland", "India", "Czech Republic", "Slovakia", "Poland", "Hungary", "Malaysia", "Thailand"}
on ActionA()
say "You chose United Kingdom"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'UKMAC'"
return
end ActionA
on ActionB()
say "You chose Ireland"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'IEMAC'"
end ActionB
on ActionC()
say "You chose India"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'INMAC'"
end ActionC
on ActionD()
say "You chose Czech Republic"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'CZMAC'"
end ActionD
on ActionE()
say "You chose Slovakia"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'SKMAC'"
end ActionE
on ActionF()
say "You chose Poland"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'PLMAC'"
end ActionF
on ActionG()
say "You chose Hungary"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'HUMAC'"
end ActionG
on ActionH()
say "You chose Malaysia"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'MYMAC'"
end ActionH
on ActionI()
say "You chose Thailand"
do shell script "/usr/local/bin/jamf setComputerName -useSerialNumber -prefix 'THMAC'"
end ActionI
set ListA to (choose from list Options with prompt "IMPORTANT: Please select the region your Mac belongs to" with title "Computer Naming") as text
if ListA is "UK" then
ActionA()
end if
if ListA is "Ireland" then
ActionB()
end if
if ListA is "India" then
ActionC()
end if
if ListA is "Czech Republic" then
ActionD()
end if
if ListA is "Slovakia" then
ActionE()
end if
if ListA is "Poland" then
ActionF()
end if
if ListA is "Hungary" then
ActionG()
end if
if ListA is "Malaysia" then
ActionH()
end if
if ListA is "Thailand" then
ActionI()
end if
return
Posted on 09-19-2017 10:57 AM
If I had to take a guess, I'd say it's getting stuck in a loop because it's not able to display the user selection dialog. Since the entire script is running as root, and the OS tends to block Applescript calls that use any type of interaction with the logged in user, unless it's run AS the user, it's probably just getting stuck and not exiting properly.
So for one, you will need to look at a way the script can run the user selection as the user, not as root. Please see these threads for some possible examples of how to address that.
Second, your Applescript is kind of unwieldy as written. Since you are starting off with a bash/shell script and then doing an Applescript, why not only use the Applescript for the user selection step and rely on bash for the rest. This would make the script easier to work with as you can use something like a case statement to set up the right computer name and/or actions. Just my opinion anyway.
Posted on 09-20-2017 06:09 AM
Thanks very much for the reponse, 'unwieldy' is probably an understatement for that script! I'm still learning at the moment.
I will take your advice and do some research on your threads, keep you posted :)