How can I toggle network services with a script?
Use the -listallnetworkservices option to get all services.

tail -n +2 to delete the first line which contains "An asterisk (*) denotes that a network service is disabled."

sed 's/^*//' to delete the asterix character at beginning of each line

while read thisName to loop



The script:

if get_status() is "Enabled" then
    set val to "off"
else
    set val to "on"
end if
do shell script "networksetup -listallnetworkservices | tail -n +2 | sed 's/^*//' | while read thisName; do networksetup -setnetworkserviceenabled  \"$thisName\" " &amp; val &amp; "; done" with administrator privileges
display dialog "Status: " &amp; (get_status()) with title "Network Toggle" buttons {"OK"} default button 1

on get_status()
    set status to do shell script "networksetup -getnetworkserviceenabled Ethernet"
end get_status




sudo in a do shell script command doesn't work on my system, I use administrator privileges.