Skip to content

Prefer networksetup and skip root runs#30

Open
gileswells wants to merge 3 commits intoeprev:masterfrom
gileswells:master
Open

Prefer networksetup and skip root runs#30
gileswells wants to merge 3 commits intoeprev:masterfrom
gileswells:master

Conversation

@gileswells
Copy link

Primarily I wanted to incorporate @amartignoni's simplification through networksetup over use of a private API and implement a fix for issue #28 so that I had a one stop branch that would do what I needed.

This covers both scenarios.

Closes #29

@smilinggoat
Copy link

Turns out this breaks support for SSIDs with spaces in the name. It only matches the final " lastword".

@KuuDS
Copy link

KuuDS commented Apr 8, 2024

fix for SSIDs with spaces

networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | xargs networksetup -getairportnetwork | sed 's/[^:]*: //'

@smilinggoat
Copy link

fix for SSIDs with spaces

networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | xargs networksetup -getairportnetwork | sed 's/[^:]*: //'

That worked for me. Thanks!

@fujimite
Copy link

fujimite commented Oct 1, 2024

fix for SSIDs with spaces

networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | xargs networksetup -getairportnetwork | sed 's/[^:]*: //'

Unfortunately this is broken as of MacOS 15.0. And I haven't been able to find any way to fix it without sudo, as every non-sudo command I've found lists the SSID as "<redacted>"

@CalumnShearer
Copy link

CalumnShearer commented Oct 10, 2024

Try system_profiler SPAirPortDataType | grep -A2 'Status: Connected' | tail -n1 | sed 's/:$//' | xargs

@pbernicchi
Copy link

I know this PR is still technically open so I'll mention that I have been trying to find a repeatable, non-root way to retrieve the active SSID (without introducing 2-3 seconds of latency as system_profiler runs - which, for me is still redacting as of macOS 26.3).

I've been using locationchanger for many years. I will likely wind up forking this project and updating the prep and script that has restored full functionality for me. I use it for automatically changing proxy settings tied to work/home locations. If it looks like this project has aged out, I will post the fork here and as a reply to the open Issue.

@kkovaletp
Copy link

As this PR came up in my inbox, I'd like to share the working and faster solution I currently use in this script on MacOS 26.2 to get the active SSID:

ipconfig getsummary en0 | grep ' SSID' | awk '{print $3}'

Hope that it is useful for you too.

@pbernicchi
Copy link

Hi,

Yep - that's where I landed as well, but I used

ipconfig getsummary en0 | grep ' SSID' | awk -F ': ' '{print $2}'

Where the additional awk arguments account for SSIDs with spaces like "John's iPhone," etc.

I've submitted PR #33 on this project but I have forked the patched script to my own repo at https://github.com/pbernicchi/locationchanger until a decision can be made by the original author on long-term maintenance. Happy to take it on as a transfer or standalone.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants