yuwe
yuwe

Reputation: 159

How to use applescripts do shell script without quotes

I have a program in bash that will change my shown MAC Address. I want to make this program into an applescript using "do shell script". However, whenever I run the code in the "do shell script" function, it does not work. This is strange because it works in terminal.

This is on my Mac computer, and I believe it to be an issue with the required quotes after the "do shell script" function. I have tried changing the quotation order, but it does not seem to work.

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

Here is the base code

do shell script "sudo ifconfig en0 ether "$(openssl rand -hex 6 | sed 's/../&:/g;s/:$//')"" with administrator privileges

Here is the AppleScript variation of this code.

It was expected that this code would change my MAC Address, but instead it returned a "error -212"

Upvotes: 0

Views: 126

Answers (1)

red_menace
red_menace

Reputation: 3412

Not sure what error -212 is, but in AppleScript, the (double) quote is used to delimit strings, so to use it in a string it needs to be escaped with a backslash, for example

do shell script "ifconfig en0 ether \"$(openssl rand -hex 6 | sed 's/../&:/g;s/:$//')\"" with administrator privileges

Note that sudo shouldn’t be used with administrator privileges - see Apple’s Technical Note TN2065.

Upvotes: 1

Related Questions