Skip to main content
Question

Dropdown menu script to install specific comp policy


Forum|alt.badge.img+6

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

7 replies

Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • August 15, 2019

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

Forum|alt.badge.img+6
  • Author
  • Contributor
  • 11 replies
  • August 15, 2019

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


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • August 15, 2019

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


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 11 replies
  • August 30, 2019

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


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • August 31, 2019

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


howie_isaacks
Forum|alt.badge.img+23
  • Esteemed Contributor
  • 772 replies
  • September 14, 2021
tlarkin wrote:

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

This helped me. Thanks!


Forum|alt.badge.img+5
  • Contributor
  • 30 replies
  • January 4, 2023
tlarkin wrote:

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

Is there away to change make a selection to something else?

 


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