Applescript to detect existing ad hoc network?

Hi I am very new Automator and applescripting. This is kind of an involved question, so I will start out with the short version and then do some explaining later on down the line.

Short version: I need an applescript to put at the beginning of an Automator app to check if a specific ad hoc network exists (ePan) and if it does, I want to select it and have the Automator app end, and if it doesn’t exist then continue to create it.

Long version: I used Automator to create an app that creates an ad hoc network with a specific name, “ePan”. Then I used sleepwatcher to make a script for executing the app on start up and wake up. For the most part it’s all working well, but there’s one anomaly I can’t figure out. The problem is that sometimes when the computer goes to sleep, or even shuts down, the ad hoc network is not removed from the list of networks, so upon re-execution of the script there’s a failure of “This network already exists.” And the Automator app never finishes.

The computer that is creating the ad hoc network is a mac mini running snow leapord. It has no screen, mouse, or keyboard attached to it in the field. I am using VNC to connect my iPad to the Mac Mini’s ad hoc network and screen share. This works great, except that I can’t always rely on the Mac Mini to get the ad hoc network set up.

Now, you might say, well if you are getting the error that the network already exists, then just connect to it from the iPad and use VCN to shut the app down via the screen share. There’s the rub. The “existing network” doesn’t actually exist. At least, it’s not available to me on the iPad.

Any ideas???

Hi

I woud like to know the answer to this question as well.

In short, I have been trying with various shell scripts to determine the name of the WiFi network that the Mac isconnected to - that is to say the network name that shows up as connected when you click on the WifI icon in the menubar.

I cannot find any quick way to this variable.

Or if it is not connected at all (because none of the networks listed under the WifI are known), presumably some variable somewhere has a null value.

Can anyone help?

Cheers

Some progress:

If I enter this in Terminal:

It returns the name of the WiFi Network. But When I try to turn this into a shell script like this:

set NetworkName to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I|grep " SSID: "|cut -c 18-"

…it throws an error when compiling. It is something to do with the quotes around SSID. How do I properly type this into a shell script?

Thanks

… and the simple solution in the end is:

set CurrentNetwork to do shell script "networksetup -getairportnetwork en1"

This returns the name of the connected network, or if the WiFi is off or not connected, CurrentNetwork will return:

:slight_smile:

Why does “man networksetup” in terminal not throw up this option - ie. get airportnetwork?

Weird. Would have saved considerable time(: