Hi.
I can’t help with client ID fields (there’s no mention of them in scutil’s “man” page), but here are a few comments about the AppleScript code, if you’ll take them:
‘choose from list’, unlike other dialogs, returns ‘false’ if the user clicks the cancel button, so you need to deal with this possibility. If you want it to stop the script like any other dialog, simply generate a “User canceled.” error:
set _Heading to choose from list {"AHEC", "CFL", "COMP", "CRSO", "DCCRP", "DCRU", "DERM", "DFC", "DHC", "DLAB", "DLAR", "DMG", "DOM", "FRP", "GI", "GME", "IA", "IMMU", "INDP", "IPIDH", "IRB", "MCDEV", "MEDE", "MEH", "MRC", "OAWA", "OBGN", "OCRC", "OLV", "OOC", "OPS", "ORTHO", "PEDS", "PULM", "RA", "RON"} with prompt "Select Department" default items {"AA"} OK button name "Ok" cancel button name "Cancel"
if (_Heading is false) then error number -128 -- Stop the script if cancel button clicked.
‘characters 1 thru -5 of theserial as text’ should be ‘text 1 thru -5 of theserial’. The former is is a two-stage process which creates a list of characters and then coerces it to text, so the final result is influenced by the current value of AppleScript’s text item delimiters. ‘text 1 thru -5 .’ extracts the required text directly and is thus more efficient and not affected by text item delimiters.
A similar consideration applies in the three lines ending with ‘as string’ after that. ‘_Heading’ is a list (the result from ‘choose from list’). Concatenating text values to a list results in another list containing the original list’s contents and the concatenated values as separate items ” and coercing a list to string (or text), as I said above, is influenced by the value of AppleScript’s text item delimiters. It would be better, once you’ve established that ‘_Heading’ isn’t ‘false’, to extract the text from it then. That way, you’ll be concatenating text directly to text, the coercion will be unnecessary, and the delimiters won’t get a look in:
set _Heading to choose from list {"AHEC", "CFL", "COMP", "CRSO", "DCCRP", "DCRU", "DERM", "DFC", "DHC", "DLAB", "DLAR", "DMG", "DOM", "FRP", "GI", "GME", "IA", "IMMU", "INDP", "IPIDH", "IRB", "MCDEV", "MEDE", "MEH", "MRC", "OAWA", "OBGN", "OCRC", "OLV", "OOC", "OPS", "ORTHO", "PEDS", "PULM", "RA", "RON"} with prompt "Select Department" default items {"AA"} OK button name "Ok" cancel button name "Cancel"
if (_Heading is false) then error number -128 -- Stop the script if cancel button clicked.
set _Heading to item 1 of _Heading -- If not stopped, get the text from the returned list.
set theserial to do shell script "system_profiler SPHardwareDataType | grep 'Serial Number (system)' | awk '{print $NF}'"
set _Name to (text 1 thru -5 of theserial) -- Extract text directly.
set _FinalName to _Heading & "-" & _Name -- Concatenate text to text.
do shell script "scutil --set ComputerName " & _FinalName
set _EthernetClientID to _Heading & "-" & "e" & _Name -- Ditto.
display dialog _EthernetClientID
set _AirportClientID to _Heading & "-" & "w" & _Name -- Ditto.
display dialog _AirportClientID
In your last two lines, ‘as’ isn’t a coercion but an optional parameter of ‘do shell script’. It tells AppleScript how to understand the data returned by the shell script rather than telling it to coerce them to another form. To coerce a shell script result to string, you’d use parenthesis to separate the ‘as’ from the ‘do shell script’:
(do shell script "scutil --set EthernetClientID " & _EthernetClientID) as string
But ‘do shell script’ returns results as text by default anyway, so ‘as string’ is superfluous at best and may be wrong as a parameter in some cases.