2

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?

1 Answer 1

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"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .