想实现连接公司 wifi 自动静音,有没有什么方案呀
1
sue0917 248 天前
iphone 不是有捷径吗,mac 没有吗
|
![]() |
2
cnscud 248 天前 ![]() /etc/ppp/ip-up
#!/bin/sh case "$5" in 192.199.1.100) osascript -e "set volume 0" ;; 172.16.0.11) /sbin/route add -net 192.168.253 -interface $1 ;; *) esac |
3
cuixiao603 OP @cnscud #2 新建一个 ip-up 把脚本放进去好像没用呀
#!/bin/sh case "$5" in 192.168.137.35) osascript -e "set volume 0" ;; *) esac |
![]() |
5
altchen 248 天前 ![]() |
![]() |
6
cnscud 248 天前
里面的 IP 是你的网络的网关地址
|
![]() |
7
cnscud 248 天前
@cuixiao603 里面的 IP 是你的网络的网关地址, 不确定的话, 你可以打印 $5 出来看看
|
9
cuixiao603 OP @cnscud #7 感觉是 连接 wifi 时候 脚本没有被调用
|
![]() |
10
minamike 248 天前 ![]() 用 launchctl 每几秒运行一下检查 ip 地址然后静音的脚本
https://www.jifu.io/posts/2733308530/ |
![]() |
11
xem 248 天前 ![]() 据说 hammerspoon 可以解决你这个需求,我没实现过,你可以研究一下
|
![]() |
12
wg5945 248 天前 ![]() https://github.com/eprev/locationchanger
然后静音的命令是 osascript -e "set volume output muted 1" 连接其他 wifi 的话 osascript -e "set volume output muted 0" 关闭静音 |
![]() |
13
willis 248 天前
hammerspoon 才是正解
|
![]() |
14
mMartin 247 天前
hammerspoon 正解 我实现过连接某个 WiFi 自动连接 smb
|
15
cuixiao603 OP 通过 hammerspoon 实现了代码如下:
function ssidChangedCallback() ssid = hs.wifi.currentNetwork() if (ssid == "yyyyyyy" or ssid == "xxxxxxxx") then hs.audiodevice.defaultOutputDevice():setVolume(0) end end wifiWatcher = hs.wifi.watcher.new(ssidChangedCallback) wifiWatcher:start() |