matryer / xbar

Put the output from any script or program into your macOS Menu Bar (the BitBar reboot)
https://xbarapp.com
MIT License
17.45k stars 641 forks source link

How to get BSSID? `airport -I` needs `sudo` #873

Open dzg opened 1 year ago

dzg commented 1 year ago

I want to get BSSID of currently connected WiFi AP, using airport -I but it requires sudo:

sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport -I | grep BSSID

But how do run as admin via xbar?

Or is there a non-sudo way to get this?

Thanks

glowinthedark commented 1 year ago

one possible workaround is to use applescript and accept the GUI sudo prompt.

Example of disabling sleep with pmset:

osascript -e 'do shell script "/usr/bin/pmset -a disablesleep 1" with administrator privileges'

IF you do not want any prompts at all, then you can allow passwordless sudo on a specific binary.

# 1. Type in terminal: sudo visudo
# 2. Append the following line at the end of the file:

your_username_here        ALL = NOPASSWD: /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport

None of the solutions above are nice; the cleanest way to work around this would be running a privileged helper in a separate process, but that's an entire different discussion.

Won't even mention setting suid on the binary as that is in the /System folder and will require disabling system protection