SECURE PIPES 2 用户指南

截图使用英文界面,图表随指南语言切换。控件名称可能因您选择的应用语言而异。

AppleScript — 命令参考

使用与 Mac App 自动化页面一致的命令说明和可复制示例,涵盖已有命令及 2.0.17 新增命令。

AppleScript 命令参考

下列章节直接同步自 Mac App 内置的自动化资料,包含逐项命令说明和完整脚本示例。执行前请替换示例名称与 ID。示例可能修改真实连接和设置,不要将整页作为脚本一次执行。

命令参考

按此处的命令短语调用。连接名或组标签需要放在引号中。

start

启动 Secure Pipes,但不显示窗口。

tell application "Secure Pipes" to start

show

显示 Secure Pipes 窗口。

tell application "Secure Pipes" to show

hide

隐藏窗口,Secure Pipes 和连接继续运行。

tell application "Secure Pipes" to hide

shutdown

退出 Secure Pipes 并停止活动连接。

tell application "Secure Pipes" to shutdown

list connections

列出已保存的连接。

tell application "Secure Pipes" to list connections

list connection groups

列出用作连接组的标签。

tell application "Secure Pipes" to list connection groups

connect connection "Build Tunnel (Local Forward)"

启动已保存的连接。

tell application "Secure Pipes" to connect connection "Build Tunnel (Local Forward)"

disconnect connection "Build Tunnel (Local Forward)"

停止已保存的连接。

tell application "Secure Pipes" to disconnect connection "Build Tunnel (Local Forward)"

connection status "Build Tunnel (Local Forward)"

读取连接当前状态。

tell application "Secure Pipes" to connection status "Build Tunnel (Local Forward)"

connect group "engineering"

按保存的启动设置启动分组。

tell application "Secure Pipes" to connect group "engineering"

disconnect group "engineering"

停止分组及其成员连接。

tell application "Secure Pipes" to disconnect group "engineering"

脚本建议使用连接 UUID,重命名后仍有效。也支持唯一名称或包含类型的完整名称;名称重复时请使用 UUID。

远程桌面

list remote desktops

列出已保存的 RDP/VNC 连接。

tell application "Secure Pipes" to list remote desktops

get remote desktop "<ID>"

按 ID 读取连接,不返回凭据。

tell application "Secure Pipes" to get remote desktop "DESKTOP-ID"

create remote desktop <JSON>

提供 name 和 values 创建连接。使用 hostProfileUUID 引用预设主机。

tell application "Secure Pipes" to create remote desktop "{\"name\":\"Office desktop\",\"values\":{\"hostProfileUUID\":\"PRESET-HOST-ID\",\"remoteDesktopType\":\"rdp\",\"remoteDesktopUsername\":\"alice\",\"remoteHost\":\"192.168.1.91\"}}"
tell application "Secure Pipes" to create remote desktop "{\"name\":\"Office VNC\",\"values\":{\"hostProfileUUID\":\"PRESET-HOST-ID\",\"remoteDesktopType\":\"vnc\",\"remoteDesktopVNCOpenMode\":\"screenSharing\"}}"

update remote desktop <JSON>

按 id 更新;name 和 values 可选。

tell application "Secure Pipes" to update remote desktop "{\"id\":\"DESKTOP-ID\",\"values\":{\"remoteDesktopOptions\":{\"screen mode id\":1,\"audiomode\":2}}}"

open remote desktop "<ID>"

必要时先启动 SSH 隧道,再打开已选的 RDP/VNC 客户端。

tell application "Secure Pipes" to open remote desktop "DESKTOP-ID"

delete remote desktop "<ID>"

按 ID 删除未连接的远程桌面连接。

tell application "Secure Pipes" to delete remote desktop "DESKTOP-ID"

允许写入用户名,但不会读取已有用户名。SSH 密码和身份文件请在 Secure Pipes 中设置;远程桌面密码请在客户端输入。

任务计划

创建和管理定时操作。读取任务计划时会脱敏,绝不会返回密码或私钥内容。

list task plans

以脱敏 JSON 列出已保存的任务计划。

tell application "Secure Pipes" to list task plans

get task plan "work-start"

按 ID 读取一个任务计划,返回脱敏 JSON。

tell application "Secure Pipes" to get task plan "work-start"

create task plan <JSON>

创建经过校验的任务计划。动作中使用连接或分组 ID,不要包含凭据。

tell application "Secure Pipes"
    create task plan "{\"id\":\"work-start\",\"hour\":9,\"minute\":0,\"repeat\":2,\"actions\":[{\"type\":\"start_group\",\"id\":\"work\"}]}"
end tell

update task plan <JSON>

提供已有 ID 和要修改的字段,更新已保存的任务计划。

tell application "Secure Pipes"
    update task plan "{\"id\":\"work-start\",\"hour\":8,\"minute\":45,\"repeat\":2,\"actions\":[{\"type\":\"start_group\",\"id\":\"work\"}]}"
end tell

set task plan enabled "work-start"

启用或停用任务计划,不改变其时间安排。省略参数时默认为启用。

tell application "Secure Pipes" to set task plan enabled "work-start" enabled false
tell application "Secure Pipes" to set task plan enabled "work-start" enabled true

run task plan "work-start"

立即执行已保存的任务计划,并返回 JSON 执行结果。

tell application "Secure Pipes" to run task plan "work-start"

delete task plan "work-start"

按 ID 删除已保存的任务计划。

tell application "Secure Pipes" to delete task plan "work-start"

JSON 模型支持重复值 0–6、自定义星期、ISO 8601 或 YYYY-MM-DD 日期范围,以及经过校验的动作。请先使用 list connections 和 list connection groups 获取 ID。

规则与使用场景

修改规则或切换场景时,可使用 ID 或唯一名称。切换场景会断开活动连接,然后重新连接。删除场景不会删除规则;没有其他所属场景的规则会变为通用规则。

list proxy rules

按顺序列出规则的 ID、名称、启用状态、动作和关联场景 ID。

tell application "Secure Pipes" to list proxy rules

list scenarios

列出场景(包括通用场景)的 ID、名称及是否正在使用。

tell application "Secure Pipes" to list scenarios

current scenario

显示当前使用场景的名称。

tell application "Secure Pipes" to current scenario

switch scenario "Office"

按 ID 或唯一名称切换场景,并按新规则重新连接受影响的连接。

tell application "Secure Pipes" to switch scenario "Office"

enable proxy rule "Work websites"

按 ID 或唯一名称启用规则。

tell application "Secure Pipes" to enable proxy rule "Work websites"

disable proxy rule "Work websites"

禁用规则,但不删除规则。

tell application "Secure Pipes" to disable proxy rule "Work websites"

set rule scenarios "Work websites" scenarios {"Office", "Travel"}

替换规则关联的场景。指定 Universal 可将其设为通用规则。

tell application "Secure Pipes" to set rule scenarios "Work websites" scenarios {"Office", "Travel"}

create scenario "Travel"

使用唯一名称创建场景,并返回其 ID。

tell application "Secure Pipes" to create scenario "Travel"

rename scenario "Travel" to "Mobile work"

重命名场景,保留现有规则关联。

tell application "Secure Pipes" to rename scenario "Travel" to "Mobile work"

delete scenario "Travel"

删除场景,但保留规则。没有关联其他场景的规则将变为通用规则。

tell application "Secure Pipes" to delete scenario "Travel"

综合示例

tell application "Secure Pipes"
    set savedRules to list proxy rules
    set savedScenarios to list scenarios
    set selectedScenario to current scenario
    switch scenario "Office"
    enable proxy rule "Work websites"
    disable proxy rule "Work websites"
    set rule scenarios "Work websites" scenarios {"Office", "Travel"}
    set rule scenarios "Work websites" scenarios {}
    set newScenarioID to create scenario "Travel"
    rename scenario newScenarioID to "Mobile work"
    delete scenario newScenarioID
end tell

代理与网络共享

共享沿用已保存的地址、端口和认证设置。启动时会按需打开现有确认窗口;网关模式仍需风险确认和 macOS 授权。

list proxy servers

列出代理服务器的 ID、名称、类型和地址,不包含认证信息。

tell application "Secure Pipes" to list proxy servers

transparent proxy status

查看透明代理运行状态、系统扩展状态及版本是否匹配。

tell application "Secure Pipes" to transparent proxy status

initialize transparent proxy

安装或修复系统扩展。macOS 可能要求批准;此命令不会启动透明代理。

tell application "Secure Pipes" to initialize transparent proxy

start transparent proxy

系统扩展就绪后,按当前路由规则启动透明代理。

tell application "Secure Pipes" to start transparent proxy

stop transparent proxy

停止透明代理。网络共享依赖此服务运行。

tell application "Secure Pipes" to stop transparent proxy

network sharing status

查看共享和网关状态。运行时显示实际生效的模式,停止时显示已保存的模式。

tell application "Secure Pipes" to network sharing status

set sharing modes "both"

选择下次手动启动时的代理模式、网关模式、两者同时启用或全部关闭。更改前需停止共享。

tell application "Secure Pipes" to set sharing modes "both"

start network sharing

按已选模式和保存的地址、端口、认证设置启动共享。可能需要确认。

tell application "Secure Pipes" to start network sharing

stop network sharing

停止网关和共享代理监听器。透明代理继续运行。

tell application "Secure Pipes" to stop network sharing

综合示例

tell application "Secure Pipes"
    set servers to list proxy servers
    set proxyState to transparent proxy status
    initialize transparent proxy
    start transparent proxy
    set sharing modes "both"
    set sharingState to network sharing status
    start network sharing
    stop network sharing
    stop transparent proxy
end tell

连接、活动与日志

使用列表返回的 ID 精确查询;详情以 JSON 文本返回。

group status "engineering"

查看分组结果和每个成员的连接状态。

tell application "Secure Pipes" to group status "engineering"

wait for connection "Build Tunnel" timeout 30

等待连接就绪;失败或超时会返回错误。

tell application "Secure Pipes" to wait for connection "Build Tunnel" timeout 30

preview route "example.com" port 443

预测当前场景下的本地规则匹配;不测试实际连通性。

tell application "Secure Pipes" to preview route "example.com" port 443 application "com.apple.Safari" transport "TCP"

test proxy server "proxy-id"

测试已保存的代理,返回结果、原因和耗时。

tell application "Secure Pipes" to test proxy server "proxy-id"

list active flows "PROXY"

查看代理活动;LAN 查看共享,ALL 查看两者。

tell application "Secure Pipes" to list active flows "PROXY"

list active flows "LAN"

查看网络共享连接。

tell application "Secure Pipes" to list active flows "LAN"

end active flow "flow-id"

按 ID 关闭一条已连接的流。

tell application "Secure Pipes" to end active flow "flow-id"

list recent logs

查看最近最多 200 条已脱敏日志,最新的在前。

tell application "Secure Pipes" to list recent logs

log detail "log-id"

按 ID 查看近期日志的完整记录。

tell application "Secure Pipes" to log detail "log-id"

终端示例

在终端中使用 osascript 执行 AppleScript 命令。macOS 可能会询问是否允许终端控制 Secure Pipes。

列出连接组

osascript -e 'tell application "Secure Pipes" to list connection groups'

输出示例

engineering, on-call

连接标签决定分组成员。启动分组时会遵循保存的顺序、并发或顺序模式及错误处理设置。

启动或停止连接组

osascript -e 'tell application "Secure Pipes" to connect group "engineering"'
osascript -e 'tell application "Secure Pipes" to disconnect group "engineering"'

查看并控制连接

osascript -e 'tell application "Secure Pipes" to list connections'
osascript -e 'tell application "Secure Pipes" to connection status "Build Tunnel (Local Forward)"'
osascript -e 'tell application "Secure Pipes" to connect connection "Build Tunnel (Local Forward)"'

从终端运行

保存文件后,将文件路径传给 osascript:

osascript ~/Scripts/Connect\ Tunnel.applescript

以脚本文件运行

将示例保存为 .applescript 文件,然后在脚本编辑器中运行,或使用 osascript 执行。

按名称连接

将示例连接名替换为 list connections 返回的名称。

on run
    -- Leave this blank to skip opening a URL after connecting.
    set postConnectURL to ""
    -- Get the saved connections.
    tell application "Secure Pipes"
        set availableConnections to list connections
    end tell
    if (count of availableConnections) is 0 then return

    set selectedConnection to choose from list availableConnections
    if selectedConnection is false then return
    set targetConnection to item 1 of selectedConnection

    -- Start the selected connection and wait up to 90 seconds.
    tell application "Secure Pipes"
        connect connection targetConnection
        set currentState to "connecting"
        repeat with attempt from 1 to 90
            set currentState to connection status targetConnection
            if currentState is "connected" then exit repeat
            if currentState is "authentication failed" or currentState is "unknown host key" or currentState is "host key changed" or currentState is "invalid" or currentState is "error" then exit repeat
            delay 1
        end repeat
    end tell
    -- Open the URL only if the connection comes up.
    if currentState is "connected" and postConnectURL is not "" then
        open location postConnectURL
    end if
    return currentState
end run

选择并启动连接组

列出可用标签,选择一个组,并启动其中的所有连接。

on run
    -- Get the groups saved in Secure Pipes.
    tell application "Secure Pipes"
        set availableGroups to list connection groups
    end tell
    -- Let the user know if there are no groups to choose from.
    if (count of availableGroups) is 0 then
        display dialog "No tagged connection groups are available." buttons {"OK"}
        return
    end if

    -- Ask which group to start.
    set selectedGroup to choose from list availableGroups
    if selectedGroup is false then return
    set targetGroup to item 1 of selectedGroup

    tell application "Secure Pipes"
        connect group targetGroup
    end tell
end run

自动化权限

macOS 询问时,请在“系统设置”>“隐私与安全性”>“自动化”中允许运行脚本的应用(例如终端或脚本编辑器)控制 Secure Pipes。

基于 Secure Pipes 2.0.17 · 更新于 2026 年 11 月 9 日