JaminT
V2EX  ›  macOS

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

  •  
  •   JaminT · Sep 13, 2021 · 3953 views
    This topic created in 1887 days ago, the information mentioned may be changed or developed.

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

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

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

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

    连接其他 wifi 的话 osascript -e "set volume output muted 0" 关闭静音
    willis
    willis
    Sep 13, 2021
    13
    hammerspoon 才是正解
    mMartin
    mMartin
    Sep 14, 2021
    14
    hammerspoon 正解 我实现过连接某个 WiFi 自动连接 smb
    JaminT
    JaminT
    OP
    Sep 23, 2021
    15
    通过 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()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2181 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 13:23 · PVG 21:23 · LAX 05:23 · JFK 08:23
    ♥ Do have faith in what you're doing.