automator ethernet toggle high sierra
You might not need administrator privileges (I don't need them in order to toggle Wi-Fi on/off). But the problem you're having is likely because you didn't put "Ethernet 1"
in quotes. So, assuming your ethernet connection is, indeed, called "Ethernet 1", then the command to turn your ethernet off looks like this:
on run {input, parameters}
do shell script "networksetup -setnetworkserviceenabled \"Ethernet 1\" off"
return input end run
If you want to toggle it on/off depending on its current state, then you can do this:
on run {input, parameters}
do shell script ¬
"[[ \"$(networksetup -getnetworkserviceenabled 'Ethernet 1')\" = \"Enabled\" ]] \
&& networksetup -setnetworkserviceenabled 'Ethernet 1' off \
|| networksetup -setnetworkserviceenabled 'Ethernet 1' on"
end run
But, since your entire AppleScript is, in fact, a shell command wrapped inside a do shell script
command, then I'd recommend using an Execute Shell Script action in your Automator workflow instead of an AppleScript one. Then you can simply write the command out in its naked form, which is much more sensible:
[[ "$(networksetup -getnetworkserviceenabled 'Ethernet 1')" = "Enabled" ]] \
&& networksetup -setnetworkserviceenabled 'Ethernet 1' off \
|| networksetup -setnetworkserviceenabled 'Ethernet 1' on