automator ethernet toggle high sierra I have been trying to create a service for toggling ethernet on off, but can't manage to get it right. 

It is for os x high sierra.

So far I have this, it runs with no error and it does appear on my services menu, but it does not toggle the ethernet connection. 

I have tried some code for airport and it works. But I really need it for Ethernet 1, en0.

on run {input, parameters}

(* do shell script "networksetup -setnetworkserviceenabled Ethernet 1 off" user name “xxxx” password “xxxx” with administrator privileges
do shell script "networksetup -setnetworkserviceenabled Ethernet 1 on" user name "xxxx" password "xxxx" with administrator privileges *)

return input end run


I have done some workflows recording actions for this but it just a bit creepy and it really is a hassle this way.

Any help would be so much appreciated.
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\" ]] \
         &amp;&amp; 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" ]] \
&amp;&amp; networksetup -setnetworkserviceenabled 'Ethernet 1' off \
|| networksetup -setnetworkserviceenabled 'Ethernet 1' on