V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cuixiao603
V2EX  ›  macOS

mac 如何实现连接某 wifi 后自动静音

  •  
  •   cuixiao603 · 2021-09-13 09:40:40 +08:00 · 2279 次点击
    这是一个创建于 927 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想实现连接公司 wifi 自动静音,有没有什么方案呀

    15 条回复    2021-09-23 22:14:58 +08:00
    sue0917
        1
    sue0917  
       2021-09-13 09:49:08 +08:00
    iphone 不是有捷径吗,mac 没有吗
    cnscud
        2
    cnscud  
       2021-09-13 09:56:40 +08:00   ❤️ 2
    /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
    cuixiao603
        3
    cuixiao603  
    OP
       2021-09-13 10:17:40 +08:00
    @cnscud #2 新建一个 ip-up 把脚本放进去好像没用呀
    #!/bin/sh

    case "$5" in
    192.168.137.35)
    osascript -e "set volume 0"
    ;;
    *)
    esac
    mansurx
        4
    mansurx  
       2021-09-13 10:29:49 +08:00
    @sue0917 #1 MacOS 12 才有捷径,还没发正式版
    altchen
        5
    altchen  
       2021-09-13 10:42:36 +08:00   ❤️ 1
    cnscud
        6
    cnscud  
       2021-09-13 10:49:50 +08:00
    里面的 IP 是你的网络的网关地址
    cnscud
        7
    cnscud  
       2021-09-13 10:51:15 +08:00
    @cuixiao603 里面的 IP 是你的网络的网关地址, 不确定的话, 你可以打印 $5 出来看看
    xaoflysho
        8
    xaoflysho  
       2021-09-13 10:56:13 +08:00
    @mansurx 可惜有捷径也没有自动化
    cuixiao603
        9
    cuixiao603  
    OP
       2021-09-13 10:56:14 +08:00
    @cnscud #7 感觉是 连接 wifi 时候 脚本没有被调用
    minamike
        10
    minamike  
       2021-09-13 11:01:28 +08:00   ❤️ 1
    用 launchctl 每几秒运行一下检查 ip 地址然后静音的脚本
    https://www.jifu.io/posts/2733308530/
    xem
        11
    xem  
       2021-09-13 15:46:54 +08:00   ❤️ 1
    据说 hammerspoon 可以解决你这个需求,我没实现过,你可以研究一下
    wg5945
        12
    wg5945  
       2021-09-13 16:12:50 +08:00   ❤️ 1
    https://github.com/eprev/locationchanger

    然后静音的命令是 osascript -e "set volume output muted 1"

    连接其他 wifi 的话 osascript -e "set volume output muted 0" 关闭静音
    willis
        13
    willis  
       2021-09-13 16:56:09 +08:00
    hammerspoon 才是正解
    mMartin
        14
    mMartin  
       2021-09-14 14:01:29 +08:00
    hammerspoon 正解 我实现过连接某个 WiFi 自动连接 smb
    cuixiao603
        15
    cuixiao603  
    OP
       2021-09-23 22:14:58 +08:00
    通过 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()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2302 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:11 · PVG 00:11 · LAX 09:11 · JFK 12:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.