Skip to content

Instantly share code, notes, and snippets.

@boozook
Created November 7, 2014 19:27
Show Gist options
  • Save boozook/61c78dc82327361f0bd5 to your computer and use it in GitHub Desktop.
Save boozook/61c78dc82327361f0bd5 to your computer and use it in GitHub Desktop.
Wi-Fi auto-select for "Select network"-popup in OS X
-- Talk with /System/Library/CoreServices/WiFiAgent.app/Contents/MacOS/WiFiAgent
-- For example for my wifi-hotspot named "Wi-Fi":
set myWiFiName to "Wi-Fi. Secure network."
-- Format: "{name}."
-- or if your wifi is closed: "{name}. Secure network." - ( optional variant )
tell application "WiFiAgent"
--activate
tell application "System Events"
tell process "Wi-Fi"
set axwin to (value of attribute "AXFocusedWindow")
set axchildren to (value of first item of attribute "AXChildren" of axwin)
repeat with axi in axchildren
if class of axi is equal to scroll area then
tell axi
set axtables to (value of attribute "AXContents")
class of axtables
repeat with axt in axtables
if class of axt is equal to table then
tell axt
set axrows to (value of attribute "AXChildren")
repeat with axr in axrows
if class of axr is equal to row then
set axcells to (value of attribute "AXChildren" of axr)
set axcell to first item of axcells
set axlabels to (value of attribute "AXChildren" of axcell)
repeat with axl in axlabels
set descr to (value of attribute "AXDescription" of axl)
if descr starts with myWiFiName then
tell axr
select
click value of attribute "AXDefaultButton" of axwin
return descr
end tell
end if
end repeat
end if
end repeat
end tell
end if
end repeat
end tell
end if
end repeat
end tell
end tell
end tell
-- Yes, this is pornocode. But it works. Sorry.
@boozook
Copy link
Author

boozook commented Nov 7, 2014

Usage: add to "Execute Me" pref-pane for "Wi-Fi"-process (com.apple.wifi.WiFiAgent) into "activate"-field. End.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment