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