If y'all can run Swift, here's an Xcode Swift command-line tool that displays all of the SSIDs currently connected:
//
// GetSSID
//
// Mostly from https://developer.apple.com/forums/thread/50302
//
import Foundation
import CoreWLAN
print("SSIDs:", currentSSIDs())
func currentSSIDs() -> [String] {
let client = CWWiFiClient.shared()
return client.interfaces()?.compactMap { interface in
return interface.ssid()
} ?? []
}
Slightly less code using this path than using AppleScript, and it'll run on most recent versions of macOS.
Tested with the following:
$ swiftc -v
Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: x86_64-apple-macosx13.0
$ /usr/bin/xcodebuild -version
Xcode 15.2
Build version 15C500b
$
The following is a restructured script that can be used without compiling the Swift code, with a shebang-based workaround for a bug (#68785 / #71004 / #71119) in the command line Swift tooling circa Xcode 15.2:
#!/usr/bin/env DYLD_FRAMEWORK_PATH=/System/Library/Frameworks /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
//
// GetSSID
//
// Mostly https://developer.apple.com/forums/thread/50302
//
import Foundation
import CoreWLAN
func currentSSIDs() -> [String] {
let client = CWWiFiClient.shared()
return client.interfaces()?.compactMap { interface in
return interface.ssid()
} ?? []
}
print(currentSSIDs())