Posted on 08-14-2019 09:33 AM
Hi All,
I'm looking to do something clever, but my scripting knowledge is pretty limited.
I want to create a script which pops a dialog box up on screen with a few options to select from:
London
Atlanta
Hong Kong
etc.
The option select would then install the relevant computer policy via a trigger.
I want to use to this for RescueAssist to install the correct package depending on Office location when building the laptop.
Cheers,
Steve
Posted on 08-14-2019 07:39 PM
I wrote this many years ago when I worked at jamf as a POC for a site chooser script, this may help you in the right direction. Just tested it on 10.14.6 and it still runs
#!/bin/bash
# set multiple site enrollment via one quick add package
getSite() {
theSite=$(osascript <<AppleScript
set mySites to {"Minneapolis", "Cupertino", "New York", "Hong Kong", "Amsterdam", "Eau Claire"}
set selectedSite to {choose from list mySites}
AppleScript
echo "${theSite}"
)
}
getSite
echo "${theSite}"
# now select invitation codes
# put site names with spaces in single quotes
case ${theSite} in
Minneapolis)
invCode='1234567890';;
Cupertino)
invCode='0987654321';;
'New York')
invCode='6789012345';;
'Hong Kong')
invCode='8901234567';;
Amsterdam)
invCode='3456789012';;
'Eau Claire')
invCode='4567890123';;
esac
echo "put your enrollment command here with code ${invCode}"
exit 0
Posted on 09-14-2021 01:34 PM
This helped me. Thanks!
Posted on 01-04-2023 03:32 PM
Is there away to change make a selection to something else?
Posted on 08-15-2019 06:48 AM
Thanks @tlarkin I'll take a look at this.
QQ - say I pick Amsterdam, if I want to run a command like:
jamf policy -event <triggerName>
Can I just replace the : invCode='3456789012';; part??
Cheers, Steve
Posted on 08-15-2019 09:24 AM
@sslavieroGSMA correct, you can put any unix command in there
Posted on 08-30-2019 08:23 AM
@tlarkin Does this look correct??
#!/bin/bash
# set multiple site enrollment via one quick add package
getSite() {
theSite=$(osascript <<AppleScript
set mySites to {"London", "Atlanta", "Hong Kong"}
set selectedSite to {choose from list mySites}
AppleScript
echo "${theSite}"
)
}
getSite
echo "${theSite}"
# now select invitation codes
# put site names with spaces in single quotes
case ${theSite} in
London)
jamf policy -event rescuelondon;;
Atlanta)
jamf policy -event rescueatlanta;;
'Hong Kong')
jamf policy -event rescuehongkong;;
esac
exit 0
The idea is to select the location and it will go off and run the select Policy via it's trigger.
I pop this script in a Policy, which I can use during deployment > which in turn runs the policy I want to install the correct software.
Posted on 08-30-2019 08:10 PM
It looks like it might work, have you tested it? That script I gave you I wrote really fast for either a POC or some sort of training I cannot remember as it was easily 6+ years ago at this point. You just need to test and tweak for your needs. I also had some redundant echo
commands in there when I was writing this. This is literally a 5 minute job, not much debugging and definitely no code tidy up at all. So, just make sure you keep on testing it out.