问题
I'm trying to get this GitHub project up and running on my Mac, for the purposes of automatically changing my network location when I switch physical location (based on the SSID I'm connected to). I have two problems I'm so far unable to resolve.
- I've followed the instructions to update the appropriate location names, and associated SSID's, and it largely all works as it should. However, there's one SSID that has a space in the name, and when I connect to that SSID, it falls back to "Automatic" location as it did not find a matching SSID in the list. I have updated the script as per the suggestions below to put quote marks in all the places they are missing, but the issue appears to be in getting the SSID in the first place. The log file echoes the new SSID name, and if my SSID were
my wifi
it just echoesNew SSID Found: my
. So I likely just need to slightly change the line of code that gets the SSID (below), but I'm not sure how.
SSID=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | awk '/ SSID:/ {print $2}')
- I've completed the automated installation (executed
./install.sh
on the appropriate directory), and it has placed all the files in the relevant places. However, it does not automatically run whenever I switch SSID's. I can double click on the executable at any point and it will run and select the correct location, but it doesn't execute automatically, which is the whole point of the exercise. Have I missed a step somewhere?
I'm extremely new to scripting on mac and GitHub in general; my previous experience is all on Windows. So I'm probably overlooking something really simple, but I just don't have the skills yet to work out where it is.
Running macOS Catalina 10.15.2
回答1:
Nice sleuthing! It should work if you change the awk
to use a colon and a space as the field separator:
SSID=$(AIRPORTTHING| awk -F ': ' '/ SSID:/ {print $2}')
Failing that, this should work too:
SSID=$(AIRPORTTHING| sed -n 's/^ *SSID: //p')
来源:https://stackoverflow.com/questions/60049628/changing-macos-location-based-on-ssid-cant-get-script-to-run-automatically