Execute bash command if wireless network is deleted?

2

1

As part of a plist I'm writing for OS X, I need to execute the "say" command if a wireless network is successfully deleted using:

networksetup -removepreferredwirelessnetwork

If a network isn't deleted, it echos:

Network (network name) was not found in the preferred networks list

I currently have:

networksetup -removepreferredwirelessnetwork en1  &&  say "Network deleted"

(where en1 is the network interface name), but that still says "Network deleted" even if a network is not deleted.

Thoughts?

sbowenwilliams

Posted 2013-10-09T22:50:26.440

Reputation: 23

Answers

1

It means that networksetup does not behave very well and returns 0 regardless the error message. This code will print the return code 0 in both cases:

networksetup -removepreferredwirelessnetwork en1 ; echo $?

The solution is to parse the output:

networksetup -removepreferredwirelessnetwork en1 2>&1 | grep -q "was not found in the preferred networks list" && say "Network deleted"

pabouk

Posted 2013-10-09T22:50:26.440

Reputation: 5 358