Skip to main content

Guys,



I am looking for something similar. I already have a rather basic script that returns, ComputerName, LocalHostName, and HostName.



Now, I want to add to the script, with interactive function.



Enter the "new" ComputerName (which will then also be used for LocalHostName and HostName), gets set by scutil --set, then return / list the new names for all three.



thanks,



jk



#!/bin/bash



function GREEN {
tput setaf 2
}



function ENDColor {
tput op
}



echo ComputerName



GREEN
scutil --get ComputerName
ENDColor
echo LocalHostName



GREEN
scutil --get LocalHostName
ENDColor



echo HostName



GREEN
scutil --get HostName
ENDColor



echo
tput setaf 5
echo "Make sure the names all match - if they don't, tell a grown up near you!"
tput op



echo
echo
echo "press Enter to close this window"
read

When is that going to run? You could easily put something together in AppleScript then save it as an application and call it during login?


I have posted this before, but here is an example proof-of-concept script on how to get user input from an Applescript, and then put it in bash. Actually here are several examples:



#!/bin/bash

# proof of concept AppleScript interaction to end user in bash

# declare any bash variables here

##### begin user interaction #####

theAnswer=$(/usr/bin/osascript <<AppleScript
tell application "Finder"
activate
display dialog "Do you want to know the meaning of the universe?" buttons {"No","Yes"} default button 2
if the button returned of the result is "No" then
set theAnswer to No
end if
end tell
AppleScript)

/bin/echo "${theAnswer}"

if [[ ${theAnswer} == "no" ]]

then /bin/echo "They obviously have read the Hitcherhiker's Guide and know it is 42"
else /bin/echo "The Answer is 42"
fi

exit 0


another one:



#!/bin/bash

# user apple script and bash to get input from user to update asset tags in the JSS
# by Tom Larkin
# proof of concept, no warranty given, use at own risk

# get usr input from Apple Script and try to redirect output back into bash and user recon to update the JSS

/usr/bin/osascript <<-AppleScript

tell application "Finder"
activate
display dialog "Enter your asset number" default answer "Enter your asset tag number here"
set theAnswer to (text returned of result)
set cmd to "/usr/sbin/jamf recon -assetTag " & theAnswer
do shell script cmd
end tell

AppleScript


exit 0


and



# invoke Applescript to interact with user via self service for them to choose which 
# existing user account to migrate to the new user account

oldUser=`/usr/bin/osascript <<-AppleScript
tell application "Finder"
activate
display dialog "Please enter a user account you wish to migrate to this account from:
${userList}" default answer " "
set theAnswer to (text returned of result)
set oldUser to "/Users/" & theAnswer
end tell
AppleScript`

/bin/echo "oldUser: ${oldUser}"


These are all examples I have posted in the past on the list and on JAMF Nation. Hopefully, one of them can help you do this with user interaction. A lot of times I would deploy these things via Self Service and scope them out to specific IT user groups to set the proper name, then bind the client with the proper name so the computer record gets created properly, etc.



Hope this helps.



Thanks,
Tom