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.
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
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'")
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
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'")