I need some help with this script.
AppleScript that scutil --get ComputerName and then asks to check to see if we need to change the ComputerName
Everything works fine As Long As there is a ComputerName to get. Meaning the Computer Name is already set to something.
However, if the Computer Name is not already set then when the script runs the scutil --get ComputerName I receive the error: "ComputerName is not set" and the script fails.
How do I get past the "not set" error?
-- ---------------------------
set localHostName to ""
set hostName to ""
set CurrentComputerName to do shell script "scutil --get ComputerName"
set CompName to ""
if (CurrentComputerName is "not set") or (CurrentComputerName is "") or (CompName is "not set") or (CompName is "") then set DeviceNumberDialog to display dialog "Current Computer Name is: " & (CurrentComputerName) & return & return & "Do you want to change the Computer Name?" & return & return & "Please enter the device number of this computer." & return & return buttons {"Keep", "Change"} default answer "" with title "Enter Device Number" default button "Change"
if text returned of DeviceNumberDialog is equal to "Why" or text returned of DeviceNumberDialog is equal to "WhyME" then set confirmDeviceNumber to display dialog "The current Computer name is " & (CurrentComputerName) & return & return & "Are you sure you want to set this computer name to" & text returned of DeviceNumberDialog & ""?" & return & return buttons {"No", "Yes"} with title "Enter Device Number" default button "No" if button returned of confirmDeviceNumber is "Yes" then set CompName to text returned of DeviceNumberDialog end if end if
if (CompName is not "") then do shell script "scutil --get ComputerName"
do shell script "scutil --set ComputerName " & CompName with administrator privileges do shell script "scutil --set LocalHostName " & CompName with administrator privileges
display dialog "Computer Name has been changed to: " & CompName
end if
end if
-- ---------------------------