Skip to main content
Jamf Nation, hosted by Jamf, is a knowledgeable community of Apple-focused admins and Jamf users. Join us in person at the ninth annual Jamf Nation User Conference (JNUC) this November for three days of learning, laughter and IT love.

Dropdown menu script to install specific comp policy

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

Like Comment
Order by:
SOLVED Posted: by tlarkin

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
Like
SOLVED Posted: by sslavieroGSMA

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

Like
SOLVED Posted: by tlarkin

@sslavieroGSMA correct, you can put any unix command in there

Like
SOLVED Posted: by sslavieroGSMA

@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.

Like
SOLVED Posted: by tlarkin

@sslavieroGSMA

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.

Like