Developer Forums relocated!

Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.

Script no longer gets SSID. macOS 14.4 Sonoma

set mySSID to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/{print substr($0, index($0, $2))}'"


set feedback to display dialog ("You are currently connected to:


WiFi SSID: " & mySSID as string) & ". 


I used to see: "WiFi SSID: <current SSID>. Where <current SSID> is the wifi I am connected to.


Now I see: "Wifi SSID ."


This happened after the update to macOS 14.4 Sonoma.


Can anyone point me to the problem or suggest a correction that will work on macOS 14.4>



MacBook Pro 16″, macOS 14.4

Posted on Mar 11, 2024 1:34 PM

Reply
Question marked as Best reply

Posted on May 4, 2024 6:31 AM

I see two things I would change:


Separate your handlers from the script.

--end routine
return


and replace:

	set mySSID to (ca's CWWiFiClient's sharedWiFiClient)'s interface()'s ssid()
	set feedback to display dialog "You are currently connected to " & mySSID & " LAN.


With:

	set wif to ca's CWInterface's interface
	set mySSID to (do shell script "networksetup -getairportnetwork " & (wif's |name|) & " | awk '{print $4}'")
    set feedback to display dialog "You are currently connected to " & mySSID & " LAN.



This definitely works to get the SSID name string in a compiled Automator application.


Tested: Sonoma 14.4.1.

Similar questions

31 replies

Mar 13, 2024 8:09 AM in response to Diveboss164

And, how to use Apple's osascript in a Zsh script:


#!/bin/zsh

function get_SSID () {
    /usr/bin/osascript <<-AS
    use framework "CoreWLan"
    use scripting additions

    property ca : current application

    return ((ca's CWWiFiClient's sharedWiFiClient)'s interface()'s ssid()) as text
AS
}

mySSID=$(get_SSID)
print ${mySSID}
exit 0


chmod +x ./getWiFi.zsh

./getWiFi.zsh

Bifrost6


Tested: Sonoma 14.4, Zsh 5.9

Apr 24, 2024 2:12 PM in response to VikingOSX

Thank you very much.

I would need to set a variable (mySSID) with the name of the SSID as a text.


However when I use this:


use framework "CoreWLAN"
use scripting additions

property ca : current application

set wifi to (ca's CWWiFiClient's sharedWiFiClient)'s interface()

set mySSID to wifi as string

I get an error displayed:


Can't make «class ocid» id «data optr00000000005E540300600000» into type string.


How could this work?

Thank you.

Apr 25, 2024 6:28 AM in response to SRS1985

With the exception of the FileMaker Pro tell block, the preceding AppleScript works fine here on Sonoma 14.4.1 in Script Editor. You can use either cast: as string, or as text, and it will run without errors in the Script Editor.


If you cannot get that AppleScript to work, then replace it with this:


use scripting additions

set ssid to (do shell script "wdutil info | awk '/SSID/ { print $3;exit}'" with administrator privileges) as text

and then feed that ssid result to your FileMaker Pro block.



May 6, 2024 12:05 PM in response to MrHoffman

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())

Script no longer gets SSID. macOS 14.4 Sonoma

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.