如何在菜单栏中添加一个按钮来启用和禁用代理?

How to add a button in menubar for enable and disable proxy?

我是 AppleScript 新手,我需要创建新图标并将其添加到菜单栏,然后​​从终端执行命令以激活我的 socks 代理

到目前为止我做了什么:

tell application "Terminal"
    do script "networksetup -setsocksfirewallproxystate Wi-Fi on"
end tell

正如我提到的,我需要:1) 在菜单栏中创建一个切换按钮 2) 能够打开和关闭 Socks 代理

有什么想法吗? 谢谢

感谢那些帮助过我的人,我想分享这个,希望这对你有用。

我写了一个简单的代码放到这个路径下~/Library/Scripts

然后在 Preferences 选项卡下的 Script Editor.app 中启用 Show Script menu in menubar

set socksStatus to do shell script "networksetup -getsocksfirewallproxy Wi-fi | grep Enabled"

if (offset of "Yes" in socksStatus) = 0 then
    do shell script "networksetup -setsocksfirewallproxystate Wi-fi On"
    display notification "Proxy Enabled !"
else
    do shell script "networksetup -setsocksfirewallproxystate Wi-fi Off"
    display notification "Socks disabled"

end if

如您所见,当您 运行 代码时它会启用代理,如果您再次 运行 它将被禁用。

祝你有美好的一天!