根据SSID更改MacOS位置-无法使脚本自动运行 [英] Changing MacOS Location based on SSID - can't get script to run automatically

查看:118
本文介绍了根据SSID更改MacOS位置-无法使脚本自动运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Mac上启动并运行此GitHub项目 ,目的是在切换物理位置时自动更改网络位置(基于我连接的SSID).到目前为止,我有两个问题无法解决.

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.

  1. 我已经按照说明更新了适当的位置名称和相关的SSID,并且在很大程度上应该可以正常工作.但是,有一个SSID名称中有一个空格,当我连接到该SSID时,它会退回到自动"状态.位置,因为它在列表中找不到匹配的SSID.我已经按照以下建议对脚本进行了更新,以便在所有缺少的地方都加上引号,但是问题似乎出在首先获取SSID上.日志文件回显新的SSID名称,如果我的SSID为my wifi,则仅回显New SSID Found: my.因此,我可能只需要稍微更改获取SSID的代码行(如下所示),但是我不确定如何做到这一点.
  1. 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 echoes New 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}')

  1. 我已经完成了自动安装(在相应目录上执行了./install.sh),并且已将所有文件放置在相关位置.但是,无论何时切换SSID,它都不会自动运行.我可以随时双击可执行文件,它会运行并选择正确的位置,但是它不会自动执行,这是整个练习的重点.我错过了某个地方的行程吗?
  1. 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?

一般来说,我对Mac和GitHub上的脚本编写都非常陌生;我以前的经验都是在Windows上进行的.因此,我可能忽略了一些非常简单的内容,但我还没有掌握解决该问题的技巧.

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.

运行macOS Catalina 10.15.2

Running macOS Catalina 10.15.2

推荐答案

很好的侦探!如果您将awk更改为使用冒号和空格作为字段分隔符,则该方法应该起作用:

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

这篇关于根据SSID更改MacOS位置-无法使脚本自动运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆