A faster version for Sequoia 15.0–15.5 (which also determines the correct WiFi interface enX):
ipconfig getsummary "$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')" | grep ' SSID : ' | awk -F ': ' '{print $2}'
Takes 46 ms vs. 3.8 s on my system.
As of macOS 15.6, the above no longer works & returns "<redacted>". Even programmatic access through CoreWLAN appears to now require a (developer/non-ad-hoc) signed executable with location entitlements, meaning it can't really be run from a script.
There is an even-hackier CLI work-around (taking 42 ms):
en="$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')"; ipconfig getsummary "$en" | grep -Fxq " Active : FALSE" || networksetup -listpreferredwirelessnetworks "$en" | sed -n '2s/^\t//p'
Note that this won't work properly on some older versions of macOS (macOS 12 tested), because the list does not appear to be sorted in the same manner. Use an older command for getting the SSID.
Also, if GUI scripting is possible in your environment, something like the following AppleScript is an option. It takes 26 ms on my system. Note, though, that GUI scripting is prone to breakage (though perhaps not moreso than what Apple has been doing with all the networking command line tools lately! 😤). It's only tested in macOS 15 and is unlikely to work in Tahoe without modification.
tell application "System Events"
tell application process "Control Center"
-- Prepare UI element references.
set wifi_menu_bar_item_ref to a reference to (first menu bar item of menu bar 1 whose value of attribute "AXIdentifier" is "com.apple.menuextra.wifi")
set wifi_enabled_toggle_ref to a reference to (value of checkbox 1 of group 1 of window "Control Center")
set wifi_connected_toggle_ref to a reference to (last checkbox of UI element 1 of scroll area 1 of group 1 of window "Control Center" where its value is true and value of its attribute "AXIdentifier" starts with "wifi-network-")
set ssid_identifier_ref to a reference to (value of attribute "AXIdentifier" of wifi_connected_toggle_ref)
-- Open the WiFi menu if it's not already open.
if not (exists wifi_enabled_toggle_ref) then
click wifi_menu_bar_item_ref
delay 0.01 -- Just in case; doesn't appear necessary in testing.
end if
-- Get the SSID.
set wifi_enabled to contents of wifi_enabled_toggle_ref as boolean
if wifi_enabled then
if exists wifi_connected_toggle_ref then
set ssid_identifier to contents of ssid_identifier_ref
set ssid to text 14 thru -1 of ssid_identifier
else -- WiFi disconnected.
set ssid to ""
end if
else -- WiFi disabled.
set ssid to ""
end if
-- Close the WiFi menu.
click wifi_menu_bar_item_ref
-- Return the ssid.
return ssid
end tell
end tell
Note that this requires the WiFi menu bar item to be always visible.
The BSSID has similarly been restricted (prior to macOS 15.6); here's a version of the above GUI AppleScript that retrieves the BSSID (without needing sudo):
tell application "System Events"
tell application process "Control Center"
-- Prepare UI element references.
set wifi_menu_bar_item_ref to a reference to (first menu bar item of menu bar 1 whose value of attribute "AXIdentifier" is "com.apple.menuextra.wifi")
set wifi_enabled_toggle_ref to a reference to (value of checkbox 1 of group 1 of window "Control Center")
set menu_buttons_group_ref to a reference to (group 1 of window "Control Center")
set bssid_label_ref to a reference to (static text "BSSID:" of UI element 1 of scroll area 1 of group 1 of window "Control Center")
set bssid_ref to a reference to (value of static text after static text after bssid_label_ref)
-- Open the secondary WiFi menu if it's not already open.
set some_menu_open to (exists wifi_enabled_toggle_ref)
set secondary_menu_open to some_menu_open and (count buttons of menu_buttons_group_ref) is 4
set primary_menu_open to some_menu_open and not secondary_menu_open
if primary_menu_open then
click wifi_menu_bar_item_ref -- Close the primary menu.
delay 1.5
end if
if not secondary_menu_open then
key down option
click wifi_menu_bar_item_ref -- Open the secondary menu.
key up option
delay 0.01 -- Just in case; doesn't appear necessary in testing.
end if
-- Get the BSSID.
if (exists bssid_label_ref) then
set bssid to contents of bssid_ref
else -- WiFi disconnected/disabled.
if contents of wifi_enabled_toggle_ref as boolean then -- WiFi disconnected.
set bssid to "00:00:00:00:00:00"
else -- WiFi disabled.
set bssid to "00:00:00:00:00:00"
end if
end if
-- Close the WiFi menu.
click wifi_menu_bar_item_ref
-- Return the ssid.
return bssid
end tell
end tell
locationpermission under sandbox and hardened runtime for your app?CWWiFiClientworked fine for me. E.g. runningCWWiFiClient.shared().interface()!.ssid()!in the Swift repl returns my network name exactly. Could this be a sandboxing issue?