TinyShield 命令行工具 (tinyshield-cli)
tinyshield-cli 让你在终端和自己的脚本中控制 TinyShield。它提供与 MCP 服务器相同的工具。例如,构建脚本可以允许它要运行的工具,cron 任务可以导出你的规则。
命令行是 TinyShield PRO 功能。请在 TinyShield › Settings › MCP 中,与 MCP 服务器一起开启。
1. 设置
该工具位于 App 内部:
"/Applications/Tiny Shield.app/Contents/MacOS/tinyshield-cli" --help
按照 Settings › MCP 中显示的内容,将别名添加到你的 shell 配置文件(~/.zshrc):
alias tinyshield='"/Applications/Tiny Shield.app/Contents/MacOS/tinyshield-cli"'
如果使用 Setapp 版,请改用 /Applications/Setapp/Tiny Shield.app。如果 TinyShield 没有运行,命令会先在后台打开它。
2. 命令
| 命令 | 作用 |
|---|---|
tinyshield status | 版本、许可证、连接模式、Network Extension 和规则数量 |
tinyshield mode [allow-all|require-approval|block-all] | 显示或切换连接模式 |
tinyshield pending list | 正在等待审批的 App,以及它们尝试连接的地址 |
tinyshield pending allow <app>… / block <app>… | 按名称、Bundle ID、路径、pid 或 ID 允许或阻止等待中的 App(--all 表示全部) |
tinyshield pending wait [--timeout 60] | 等待,直到有 App 需要审批 |
tinyshield decisions [list|allow|block|remove] | Require Approval 模式的 App Connection Decisions |
tinyshield block-list [list|add|remove|enable|disable] | Block List |
tinyshield allow-list [list|add|remove] | Allow List |
tinyshield apps [--range 1h] [--status blocked] | 使用过网络的 App |
tinyshield app <app> 或 --pid <pid> | 单个 App 的签名、规则、活动和带宽 |
tinyshield connections <app> 或 --pid <pid> | 某个 App 连接过的域名和 IP 地址 |
tinyshield domain <domain> / tinyshield ip <ip> | 哪些 App 连接过某个域名或 IP,以及匹配它的规则 |
tinyshield tree | 以树形显示主窗口中的列表 |
tinyshield countries | App 连接过的国家,与地图中一致 |
tinyshield recently-blocked [--clear] | 最近被阻止的连接 |
tinyshield bandwidth [--timeframe day] [--app Safari] / tinyshield live | 流量使用和当前速度 |
tinyshield settings [get|set <setting> on|off] | block-list、dns、apple-programs、launch-at-login 等设置 |
tinyshield export <file> / tinyshield import <file> [--replace] | 保存或载入你的配置 |
tinyshield open <window> [--search text] | 显示 TinyShield 窗口,例如 main、block_list 或 mcp_settings |
tinyshield clear-activity --yes | 删除记录的网络活动(规则会保留) |
tinyshield tools / tinyshield call <tool> '<json>' | 列出所有工具,或用 JSON 参数调用其中一个 |
运行 tinyshield <command> --help 查看所有选项。
在 block-list add 和 allow-list add 中,以 /、~ 或 ./ 开头的值表示 App 或可执行文件,其他值则是域名、通配符(*.example.com)或 IP 地址。
3. 示例
允许构建所用的包管理器,然后运行构建:
tinyshield pending allow ~/.local/bin/uv
uv pip install -r requirements.txt
在长时间的无人值守任务开始前,预先允许要用到的工具:
tinyshield allow-list add /opt/homebrew/bin/node ~/.local/bin/uv
有 App 需要审批时发出提醒:
if tinyshield pending wait --timeout 600 --only-new; then
osascript -e 'display notification "An app is waiting for approval" with title "TinyShield"'
fi
对所有 App 阻止某个跟踪器,并查看哪些 App 连接过它:
tinyshield block-list add '*.doubleclick.net'
tinyshield domain doubleclick.net --subdomains --range 7d
4. 编写脚本
- 在任意命令后加上
--json,即可获得便于机器读取的输出。 - 加上
--no-launch,命令会直接失败,而不会打开 TinyShield。 - 退出码:
| 退出码 | 含义 |
|---|---|
0 | 成功 |
1 | 命令失败。TinyShield 不在 Require Approval 模式时,pending wait 也会以 1 退出 |
3 | 未找到。超时前没有 App 请求审批时,pending wait 也会以 3 退出 |
4 | 需要 TinyShield PRO |
69 | 无法连接 TinyShield:服务器已关闭,或 TinyShield 没有安装或没有运行(使用 --no-launch 时) |
通过命令行做出的决定,会在 TinyShield 的 Decisions 列表中显示为 Command Line。