Apple Event: May 7th at 7 am PT

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 Mar 13, 2024 1:29 PM

Here is the the complete Run Shell Script and Run AppleScript handshake that passes the SSID.



Of course as I showed you earlier, you can get the SSID from AppleScript and completely avoid using the Run Shell Script action… 😉

Similar questions

25 replies

Mar 11, 2024 9:14 PM in response to VikingOSX

This application runs on startup and gives me 60 seconds to confirm I’m connected to the correct wifi before connecting to my server. If I fail to make a decision in 60 seconds the app should attempt to connect to my server by default.


I’m getting closer, but several things still not working.


I am getting the SSID displayed in the dialog box and it’s configured properly. 


However, here is a list of issues I cannot seem to resolve. It’s after midnight and I’m calling it a day. 


  1. Refresh time is taking 60 seconds to go from 60 to 55 seconds remaining. It appears to be shorter intervals as it approaches 5 second remaining but it’s not clocking properly.
  2. Selecting the 'Connect Now' button does not run script. 
  3. Failing to make a selection does not run script.
  4. Cancel works


MacBook Pro M3 Max

Most of this script with the exception of your input comes from my older application. My older original is working with the exception of getting and displaying the SSID of the connected wifi.


Thanks for all your help.


Here is what I have so far.


use framework "CoreWLAN"

use scripting additions


property ca : current application

# property dialog_icon : "Macintosh SSD:Users:user:Automator Custom Icons:Synology 5 bay DiskStation DS1512+.icns"

property app_icon : "Macintosh SSD:Users:user:Automator Custom Icons:Synology 5 bay DiskStation DS1512+.icns" as text


set Refresh_time to 5 as integer

set wait_time to 60 as integer

set Decision to 0 as integer


repeat until (Decision > 0) or (wait_time = 0)

set Decision to my Get_User_Feedback(wait_time, Refresh_time)

set wait_time to wait_time - Refresh_time

end repeat

log (Decision) as integer


# the rest of your Decision if tests after this comment

return


# display alert "Decision is " & Decision

# 0 means no answer - Should connect without input after 60 seconds

# 1 means Connect Now

# 2 means Don't Connect


if Decision is 2 then

quit


else if Decision is 1 then

tell application "Finder"

try

mount volume "smb://VS/home/Drive"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VS/Movies"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VS/music"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VS/photo"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VS/TV Shows"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VS/video"

delay 1

end try

end tell

end if


on Get_User_Feedback(Remain_time, Step_delay)

set mySSID to (ca's CWWiFiClient's sharedWiFiClient)'s interface()'s ssid()

try

# AppleScript needs the option+L line continuation ( ¬ ) character as text does not flow from one line to the next without it.

set {gave up:gaveUP, button returned:buttonReturned} to display dialog ("You are currently connected to WiFi SSID: " & mySSID as text) & return & return & ¬

"You will be connected to the VS Server in " & Remain_time & ¬

" seconds. If your are not on VS Local Area Network, please select 'Don't Connect'." buttons {"Don't connect", "Connect Now"} default button ¬

"Connect Now" with icon app_icon as alias giving up after Remain_time

if gaveUP then

return 0

else if buttonReturned is "Connect Now" then

return 1

else

return 2

end if

end try

end Get_User_Feedback



Mar 12, 2024 2:16 AM in response to Diveboss164

Having slept on this, I would do the following:


  1. I would not use a repeat while block at all.
    1. Instead of 12 iterations of decrementing 5 seconds — do one dialog with a timeout value of however many seconds you will wait for the user response. In the message, briefly state what will happen if they fail to take action (the gaveUP condition).
  2. Obtain the SSID outside of the handler and pass that string to the handler with the time delay before the dialog gives up — as two arguments to the handler:
    1. on Get_User_Feedback(mySSID, timeout_secs)


And remove the following from your code:


# the rest of your Decision if tests after this comment
return


But, you do want a return statement just prior to your handler to separate your main script code from it.


return

on Get_User_Feedback(Remain_time, Step_delay)


Mar 11, 2024 2:13 PM in response to Diveboss164

The airport command line tool is now deprecated in Sonoma 14.4 and no longer works other than to inform you that it is deprecated and will be removed in a future release. Instead, use this:


use framework "CoreWLAN"
use scripting additions

property ca : current application

set wifi to (ca's CWWiFiClient's sharedWiFiClient)'s interface()
display dialog "You are connected to: " & wifi's ssid() as text with title "Current SSID"
return


Tested: Sonoma 14.4

Mar 11, 2024 5:22 PM in response to Diveboss164

Let's look closer at that Get_User_Feedback handler.


Here is how I would write it:


use framework "CoreWLAN"
use scripting additions

property ca : current application
# property dialog_icon : "Macintosh SSD:Users:me:Automator Custom Icons:icon.icns"
property app_icon : ((path to pictures folder) & "brain512x512_300.icns") as text

set Refresh_time to 5 as integer
set wait_time to 60 as integer
set Decision to 0 as integer

repeat until (Decision > 0) or (wait_time = 0)
	set Decision to my Get_User_Feedback(wait_time, Refresh_time)
	set wait_time to wait_time - Refresh_time
end repeat
log (Decision) as integer

# the rest of your Decision if tests after this comment
return

on Get_User_Feedback(Remain_time, Step_delay)
	
	set mySSID to (ca's CWWiFiClient's sharedWiFiClient)'s interface()'s ssid()
	
	try
		# AppleScript needs the option+L line continuation ( ¬ ) character as text does not flow from one line to the next without it.
		set {gave up:gaveUP, button returned:buttonReturned} to display dialog ("You are currently connected to WiFi SSID: " & mySSID as text) & return & return & ¬
			"You will be connected to the xyzzy Server in " & Remain_time & ¬
			" seconds. If your are not on xyz Local Area Network, please select 'Don't Connect'." buttons {"Don't connect", "Connect Now"} default button ¬
			"Connect Now" with icon app_icon as alias giving up after Remain_time
		if gaveUP then
			return 0
		else if buttonReturned is "Connect Now" then
			return 1
		else
			return 2
		end if

end try

end Get_User_Feedback


With no user input and two gave up events:



Mar 13, 2024 9:35 AM in response to VikingOSX

Thanks again VikingOSX,

I changed to your recommended Zsh script and it works at getting the SSID as well. My Automator application I wrote maybe 10-15 years ago with a few tweaks throughout the years has served me well until macOS 14.4. My application still works with the exception of providing the SSID.


The one thing I was not ready to give up is the dialog box countdown timer. So if I can find a way to get the mySSID variable into the AppleScript that's where I need guidance. Am I approaching this wrong?



Your input has guided me to read and experiment with this problem.


As a septuagenarian I try to stay active with some coding but admit I need to ask for help and sometimes spend weeks reading.


Thanks for your time.

Apr 24, 2024 2:38 PM in response to SRS1985

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()'s ssid as string

tell application "FileMaker Pro"
	activate
	set field "Wifi" of current record to wifi
end tell

I get an error displayed:

Can't make «class ocid» id «data optr0000000000AD8B0000600000» into type text.


How could this work?

Thank you.

May 3, 2024 7:23 PM in response to VikingOSX

Hi again.

I've been playing with this and the following is working great when I run it in the automator app. It counts down correctly and runs on the give_up event and the buttons work as intended. It acquires the LAN SSID and displays the information on each countdown update.



However, when I convert it to an application, the SSID information is not acquired. I get the following.



Everything else works with the exception of the acquisition and display of the current SSID.

Any ideas of what I need to do to have this run as an application and acquire and display the SSID?


Here's the code:


use framework "CoreWLAN"

use scripting additions


property ca : current application

# property dialog_icon : "Macintosh SSD:Users:user:Automator Custom Icons:Synology 5 bay DiskStation DS1512+.icns"

property app_icon : "Macintosh SSD:Users:KerryVogt:Pictures:Business Contact Logos:Image2icon:Synology 5 bay DiskStation DS1512+.icns" as text



set Refresh_time to 5 -- the delay between refresh of the dialog

set wait_time to 60 --total delay for user to decide

set Decision to 0


repeat until (Decision > 0) or (wait_time = 0)

set Decision to Get_User_Feedback(wait_time, Refresh_time)

set wait_time to wait_time - Refresh_time

end repeat


-- display alert "Decision is " & Decision

-- 0 means no answer

-- 1 means Connect

-- 2 means don't connect

if Decision is 2 then

quit

end if


-- your program here

if Decision = 1 or Decision = 0 then

tell application "Finder"

try

mount volume "smb://VogtStudios/home/Drive"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VogtStudios/Movies"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VogtStudios/music"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VogtStudios/photo"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VogtStudios/TV Shows"

delay 1

end try

end tell

tell application "Finder"

try

mount volume "smb://VogtStudios/video"

delay 1

end try

end tell

end if

-- end routine


on Get_User_Feedback(Remain_time, Step_delay)

set wait_time to 5 as integer

set mySSID to (ca's CWWiFiClient's sharedWiFiClient)'s interface()'s ssid()

set feedback to display dialog "You are currently connected to " & mySSID & " LAN.

You will be connected to the " & mySSID & " Server in " & Remain_time & ¬

" seconds. If your are not on VogtStudios Local Area Network, please select 'Don't Connect'." buttons {"Don't connect", "Connect Now"} default button ¬

"Connect Now" with icon app_icon as alias giving up after wait_time

if gave up of feedback then

return 0

else if button returned of feedback is "Connect Now" then

return 1

else

return 2

end if

end Get_User_Feedback




As always, any help is appreciated.


Mar 11, 2024 2:47 PM in response to VikingOSX

Thanks for the reply. I'm real rusty with scripting.

Can you show me where to change the script? What to remove and where to add the changes.

This is compiled to run as an application.


The BoldFace section is where I'm sure I need to change, but just removing that section and adding the scripting you provided "as is" didn't work. Yes, I'm an idiot sometimes. I've been away from this for too long.


All your help is appreciated.


Here is my original script.


set Refresh_time to 5 -- the delay between refresh of the dialog

set wait_time to 60 --total delay for user to decide

set Decision to 0

repeat until (Decision > 0) or (wait_time = 0)

set Decision to Get_User_Feedback(wait_time, Refresh_time)

set wait_time to wait_time - Refresh_time

end repeat


-- display alert "Decision is " & Decision

-- 0 means no answer

-- 1 means Connect

-- 2 means don't connect


if Decision is 2 then

quit

end if


-- your program here


tell application "Finder"

try

mount volume "smb://xyz/home/folder1"

delay 1

end try

end tell


tell application "Finder"

try

mount volume "smb://xyz/folder2"

delay 1

end try

end tell


tell application "Finder"

try

mount volume "smb://xyz/folder3"

delay 1

end try

end tell


tell application "Finder"

try

mount volume "smb://xyz/folder4"

delay 1

end try

end tell


tell application "Finder"

try

mount volume "smb://xyz/folder5"

delay 1

end try

end tell


tell application "Finder"

try

mount volume "smb://xyz/folder6"

delay 1

end try

end tell


-- end routine


on Get_User_Feedback(Remain_time, Step_delay)


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 & ". 


You will be connected to the xyzzy Server in " & Remain_time & " seconds. If your are not on xyz Local Area Network; please select 'Don't Connect'." buttons {"Don't connect", "Connect Now"} default button "Connect Now" giving up after Step_delay with icon file (("MacIntosh SSD:Users:me:Automator Custom Icons:") & " icon.icns")


if gave up of feedback then

return 0

else if button returned of feedback is "Connect Now" then

return 1

else

return 2

end if

end Get_User_Feedback

Mar 12, 2024 12:14 PM in response to Diveboss164

Ok I moved the return from here


# the rest of your Decision if tests after this comment

return


to here


return



on Get_User_Feedback(Remain_time, Step_delay)


It helps when you show me where in the code to make changes.


After doing this, it now processes the button pushes and runs automatically on timeout. That's a start, but the countdown timer is still not working.

I still want a countdown timer either continuous or incremental, which ever is easiest.


I currently left this part of the code in, but want to get a fix to it. Like I said, it's been a long time since I have done any coding.



set Refresh_time to 5 as integer

set wait_time to 60 as integer

set Decision to 0 as integer


repeat until (Decision > 0) or (wait_time = 0)

set Decision to my Get_User_Feedback(wait_time, Refresh_time)

set wait_time to wait_time - Refresh_time

end repeat


Again thanks.

Mar 12, 2024 8:12 PM in response to Diveboss164

Hi MrHoffman,

Thanks for the link. I created a shell script with Automator using this option,


!/bin/sh

##Get the wireless port ID

WirelessPort=$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')

##What SSID is the machine connected to

SSID=$(networksetup -getairportnetwork "$WirelessPort" | cut -d " " -f4)

echo "$SSID"


and it does return the SSID.


Would you mind explaining to me how I can link this to my AppleScript and pass the variable $SSID to my dialog box? Please keep in mind this is new to me and I'm learning. I still haven't how I can change/save the shell script in anything except the default 'workflow' file.

Thanks

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

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.