Currently I can do this only on a per connection basis using this script:
property status : "none"
property val : "none"
on get_status()
set status to do shell script "sudo networksetup -getnetworkserviceenabled Ethernet" as string
end get_status
get_status()
if status is "Enabled" then
set val to "off"
else
set val to "on"
end if
do shell script "sudo networksetup -setnetworkserviceenabled Ethernet " & val
get_status()
display dialog "Status: " & status with title "Network Toggle" buttons {"OK"} default button 1
But recently I am getting network from different sources and I would like to have a script with toggles availability for all active connections (either all on or all off).
Any idea on how I could pull this off?
Best Answer
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 linewhile read thisName
to loopThe script:
sudo in a
do shell script
command doesn't work on my system, I useadministrator privileges
.