1

I used this script below to change mac address randomly every time it is ran.

openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' | xargs sudo ifconfig en0 ether

ifconfig en0 | grep ether

I want Automator to do it for me. When I run this Shell Script, it runs successfully but when I actually open Terminal and run

ifconfig en0 | grep ether

to see if it changed MAC address I find out it didn't.

If i manually enter such script into Terminal, it works perfectly. What should I do?

  • I just found out this answer that solves it in more "developer friendly" way. Beware that it runs all commands as root. https://stackoverflow.com/a/6941026/1310733 – Petr Újezdský Apr 09 '22 at 22:05

2 Answers2

3

Try creating an AppleScript instead:

on run {input, parameters}
    do shell script "openssl rand -hex 6 | sed 's/\\(..\\)/\\1:/g; s/.$//' | xargs sudo ifconfig en0 ether" with administrator privileges
    do shell script "ifconfig en0 | grep ether"
    return input
end run

It should ask you to enter your adminstrator password, then change the mac address. Automater is better suited to run Applescripts generally, as shell scripts can sometimes be problematic.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • Note that if it needs to be in the form of an Automator workflow, you can use the "Run Applescript" action to include this in the workflow. It's a bit indirect (using Automator to run an AppleScript which runs a shell script), but it's the easiest way I've found to run commands as root from Automator. – Gordon Davisson May 03 '17 at 01:38
  • does this still work? I'm getting permission denied when doing this – spracketchip Dec 14 '17 at 23:46
  • @spracketchip: Yes, it worked fine for me just now when I tried (macOS 10.13.2). – l'L'l Dec 20 '17 at 22:22
0

You can place them directly in your root directory. You will need to have root privileges to access the function but it will not require pass phrase input.

oliver
  • 2,467
  • 3
  • 14
  • 29