Get available wifi network names

Hi, I am trying to develop a Script to get the name of all available wifi names, but I can’t get my script to work. I can get the name of the current wifi connection but thats it. I tried a second script to get the items name from the menu but this doesn’t work can’t get the menu by name.

Any idea in how to do this!

Thank you for your help!

Brian

hi Brian

I had a quick google and found this, i’m not sure how the numbers in the script work, but I changed them to 1 to 16
for me and it showed all of my networks, the code allows you to use true or false to see either connected or not.

tell application "System Events"
	tell current location of network preferences
		get name of every service whose (kind is greater than 1 and kind is less than 16) --and connected of current configuration is true
	end tell
end tell

heres where I found he code.
http://stackoverflow.com/questions/10399535/how-to-get-the-currently-connected-vpn-s-name-under-os-x

Hi,

you can’t do that in vanilla AppleScript.
See this thread for an AppleScriptObjC solution: http://macscripter.net/viewtopic.php?id=40307

It returns names of interface configurations for me, not the actual names of the WiFi networks.

Like StefanK mentioned, there is no vannilla applescript way, unless GUI scripting. However there is also a useful command line util named airport:

set results to paragraphs 2 thru -1 of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s | sed -nE 's/[ ]*(.*) [a-z0-9]{2}:[a-z0-9]{2}:.+/\\1/p'")

Pfffffft!

Asked about this a couple of years ago, and just remembered:

use scripting additions
use framework "Foundation"
use framework "CoreWLAN"

set currentInterface to current application's CWInterface's interface()
set networks to currentInterface's scanForNetworksWithName:(missing value) |error|:(missing value)
set networkNames to (networks's valueForKey:"ssid")'s allObjects() as list

log networkNames


My original thread is here: http://macscripter.net/viewtopic.php?pid=160424#p160424

Same link as Stefan, also updated my post so it works with ssids with spaces in it as you have asked a couple of years ago :slight_smile:

The one great thing that’s happened since then is the ability to do ASOC within AppleScript scripts, rather than having to use Xcode!

Thank you all for such good replys! the one that worked for me is the shell script:


set results to paragraphs 2 thru -1 of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s | sed -nE 's/[ ]*(.*) [a-z0-9]{2}:[a-z0-9]{2}:.+/\\1/p'")

:smiley:

Thank you all