couple of items:
1) Was your test machine a MacBook Air or Retina?
2) What was your target machine for the script?
3) did you begin your script with #!/bin/bash
the en0 would only work for an Air or Retina as en0 is the wireless interface. All other devices en0 would be ethernet and wouldn't have an SSID option available.
Something like
code:networksetup -listnetworkserviceorder | grep ": Wi-Fi" | awk -F ": " '{print $3}' | sed 's/)//g'
would find your Wi-Fi interface on a 10.8 machine and get the en# value or use system_profiler to find if the target machine is an Air or Retina the "if yes use en0 else en1".
Hi Justin,
I'm using a MacBook Air, hence en0 for wireless
Yes, I use #! /bin/bash and also tried #! /bin/sh
The networksetup -removepreferredwirelessnetwork en0 "SSID" works when I choose to run it as a command but not as a script.
Looks like TextEdit is adding some of its formatting to your script which is causing it to fail based on the error message received. Typically i prefer using TextWrangler, or just vi to write a script.
Thanks shaidar. Spot on!
I installed Text wrangler from http://download.cnet.com/TextWrangler/3000-2351_4-10220012.html
Entered the command -
networksetup -removepreferredwirelessnetwork en0 "SSID name"
Saved it with an .sh extension and pushed it through Casper Remote.
I think I've seen this when the script was not saved as a plain text file (TextEdit will let you save as a .sh when it's a rich text file). The main reason I don't use TextEdit, however, is that it lacks contextual formatting. I've got quite a collection of other apps that do (really, guys, I have a problem), and TextWrangler is among them. It's better than decent.
I use TextWrangler for almost all my scripting needs. Its free, which is hard to beat, and has some nice features, like color coding, basic syntax checking and a good find/replace functionality. I especially like the ability to run the script from within the app and get output for testing, so I can be reasonably sure my script works before uploading it to Casper Admin. Its bigger sibling BBEdit is considered one of the better options, but I never saw the need to pay for it when TextWrangler does almost all the same things for $0.
Another option is XCode, but considering XCode is such a big application, it doesn't really make sense to me to launch it, wait for it to load, etc just to write a script. Its kind of overkill for script writing.
I will only use TextEdit if I need to whip up a script while not on my primary Mac and don't have access to other better options. Otherwise I avoid it.
TW is the best (for free) But TextEdit also works fine if you:
Change pref's to use Plain Text.
Remove .txt in file name and save as .sh.
TW will win you over though with all the good advanced features. If you need more, BBEdit.
BBEdit is my go-to editor for scripts. TextWrangler works as well.
TW or BBEdit, or failing that nano/pico on the command line. I would never use textedit for editing scripts, have had too many problems in the past