Script to rename MAC not working on Catalina.

Viziri
New Contributor

Hi,

Currently I am running a script that asks the user for the machine name after the first login. On older laptops with Mojave or earlies OS the script gets triggered and runs perfectly, however on the new laptops that come with Catalina it won’t work. This is the script used. I wonder if the issue is caused by any security policies on Catalina or because it's bash and not zsh?

!/bin/bash

/usr/bin/osascript << EOF property compName : ""

repeat while compName is "" tell application "Finder" activate display dialog "What should this computer be named:" default answer compName set compName to text returned of result end tell
end repeat

try do shell script "hostname " & quoted form of compName on error errorMsg number errorNum display alert "Error " & errorNum message errorMsg buttons "Cancel" default button 1
end try
EOF

name=$(hostname)
scutil --set ComputerName "${name}"
scutil --set LocalHostName "${name}"
scutil --set HostName "${name}"

Execute the Jamf Inventory run to set the new computername at Jamf,

otherwise jamf will use for the next command "his own" computername like macbook pro

jamf recon

Execute the policy "Bind the machine to LDAP" via Trigger ADBind

jamf policy -event ADBind

Execute the policy "Set Custom DNS Searchdomains" via Trigger set-domains

jamf policy -event set-domains

Checks if Mcafee is already installed, if not, run policy McAfee Installation

if ! [ -f "/etc/ma.d/EPOAGENT3000/config.xml" ] ; then jamf policy -event install-mcafee
else VERSION="Not installed."
fi

END SCRIPT

3 REPLIES 3

talkingmoose
Moderator
Moderator

@Viziri, which part of the script isn't working? At what point does it fail?

Have you also considered using the jamf binary's setComputerName feature as well? It should do what you're trying to do with the scutil command.

Viziri
New Contributor

it's the very first part of the script that is failing..the prompt to rename the mac doesn’t appear and the other parts of the scripts don’t get triggered in the end. and yes if I run the jamf command then it works. I’m just puzzled why it doesn’t work on Catalina only and wether there’s a way to make the script work or i just should use manual command and rename the mac in the terminal.

talkingmoose
Moderator
Moderator

@Viziri, I've seen the same behavior found a solution here on Jamf Nation that resolved it for me.

Here's a link to a script I put together for a customer that works on Catalina. The important piece of it was the different way to call osascript. See line 20. It's important that you run the command now as the currently logged in user. That means you also need to get the current user's name. See line 14.

Because osascript calls AppleScript (a different scripting language), I like to put my AppleScript command in a variable (line 19) and then call it with osascript. You don't have to do that part like I did. Just follow the example on line 20.

https://gist.github.com/talkingmoose/0fbc4213fe92d305f8d72b1a0dabda53