Computer Rename Using Dropdown Boxes

casafrancisco
New Contributor III

Hi all,

I wanted to see if this is even possible, and thank you for any help or insight!

We have 3 main departments that I am managing devices for: Pharmacy, Physical Therapy, and Physician Assistants. I would to use our renaming scheme so that I can get it automated and get us closer to my ideal Zero Touch Deployment configuration.

We rename the computers based on: DEPT-USER-DEVICE
example: RX-JSMITH-IMAC, PA-JSMITH-MBP, PT-JSMITH-MBA, etc

I would love to see if we could present a user with a popup or alert that contains a dropdown box for them to select their department. This would then determine the Department part, then obviously we can get the User with $3, then I care less about the device type.

So I throw this out there, can it be done?

4 REPLIES 4

stevewood
Honored Contributor II

@casafrancisco totally possible and something we do today. We utilize country, business unit name, and a portion of the machine serial number to name computers. I spoke about it in my JNUC preso last year and you can find a sanitized version of the script we use here:

namingTEMPLATE.sh

You can walk back from that script to get to the PDF of the presentation. The slide showing the dialogs is towards the end.

Basically, we use cocoa dialog to ask for the information, then based on the info we set the name. This should do the trick to ask for the department, grab the user name and capitalize it, combine the two, and then set the name on the computer using the jamf binary.

You will obviously need to install cocoaDialog on the systems before you can run this.

#!/bin/bash

# cocoaDialog path
CD="/usr/local/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog"
currUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

department=`$CD standard-dropdown --height 125 --text "Please choose the department:" --float --no-cancel --title "Department" --items "Pharmacy" "Physical Therapy" "Physician Assistant" --string-output --icon gear`
department=`echo ${department} | cut -d' ' -f2-`

case ${department} in 
'Pharmacy')
    deptCode='RX'
    ;;

'Physical Therapy')
    deptCode='PT'
    ;;

'Physician Assistant')
    deptCode='PA'
    ;;

esac

## uppercase user name
currUser=`echo ${currUser} | tr [a-z] [A-Z]`

## buid computer name
computerName="${deptCode}-${currUser}"

# update Jamf
/usr/local/bin/jamf setComputerName -name ${computerName}

exit 0

m_donovan
Contributor III

Short answer is yes it can be done. In fact it can be done in just about any scripting language available. You could use Applescript or BASH but IMO Applescript's GUI presentations which BASH uses are disjointed. I would think that Xcode (Swift) or Python would be the way to go for what you describe. Here is a link you could use as the backbone to build on. https://github.com/jamf/Mac-Asset-Tag. This was put together by Jamf professional services and a great tool on it's own. With some Google Fu and trial and error I bet you could work out what you want to do. I am sure there are others that would recommend other approaches and there is nothing wrong that. The trick is finding what you are comfortable with and running with it.

casafrancisco
New Contributor III

@stevewood Thanks I'll check this out! Is this the one you mentioned? https://cocoadialog.com/

@m.donovan I'll check that out as well. Thanks!

stevewood
Honored Contributor II

@casafrancisco yes, but you'll not find a download for it there. I'm not even sure where a valid download link is, but you might do a search here on Jamf Nation for it. The developer, well the guy that took over development, took down all of the install links.