0

I am running the following script in Platypus but the MAC address does not change:

#!/bin/zsh

IF=en7

mac=`ifconfig $IF | awk '/ether/{print $2}'`
echo "$IF mac before change=$mac"
randmac=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`
sudo ifconfig $IF ether $randmac
mac=`ifconfig $IF | awk '/ether/{print $2}'`
echo "$IF mac after change=$mac"

Not receiving errors anymore. However, the MAC address is not changed by the script. Commands work individually pasted into Terminal, but not executed as an application by Platypus.

Platypus screenshot:

Platypus screenshot

3
  • Can you please fix your code formatting by editing your question, selecting the bash script and clicking on the „{}“ in the bar on top of the edit box?
    – nohillside
    Commented Nov 9, 2018 at 8:17
  • What part do you need help with? Does the shell script work? Commented Nov 9, 2018 at 10:31
  • Your script code has a bunch of smart-quotes and you should use straight-quotes. Also, needless use of grep | when ifconfig $IF | awk '/ether/{print $2}' does both. Commented Nov 9, 2018 at 17:21

1 Answer 1

0

Platypus

Use Platypus to create an application from your bash script. This approach avoids needing to use AppleScript.

Platypus is a developer tool that creates native Mac applications from command line scripts such as shell scripts or Perl, Ruby and Python programs. This is done by wrapping the script in a macOS application bundle along with an executable binary that runs the script.

Platypus screenshot

Other Approaches

Mathias Bynens has an article on How to create simple Mac apps from shell scripts.

Also worth reading is the related question How to make a Mac OS X .app with a shell script?

4
  • 1
    Your answr is better than the platypus one in the duplicate It would b nice if this was moved to the original
    – mmmmmm
    Commented Nov 9, 2018 at 11:00
  • If the error is related to the script not working, ask a new question specifically about the error. Otherwise, can you edit this question? Commented Nov 9, 2018 at 17:36
  • Graham - I used Platypus to create an application out of the script above. The script runs error free, but the MAC address does not get changed. Can you help me understand why that is happening? I am running Mojave 10.14.1. Commands work when run individually in Terminal, but not when compiled as an app.
    – isd503
    Commented Nov 10, 2018 at 19:50
  • sudo in your script requires root privileges. The script has no error checking, so you be getting errors but not seeing them. Commented Nov 11, 2018 at 9:16

Not the answer you're looking for? Browse other questions tagged .