You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AppleScript如何设置第三方应用弹出的Finder选择窗口目标路径?

你可以利用macOS文件选择弹窗的全局快捷键Command + Shift + G唤起路径跳转输入框,输入目标路径后即可自动导航到指定文件夹,完整实现代码如下:

set theFolderToProcess to choose folder with prompt "Step 1: Select the folder to convert:"
-- 转换为POSIX格式路径
set folderPosixPath to POSIX path of theFolderToProcess

tell application "System Events"
    tell application process "MyApp"
        set mainWindow to window "MyApp"
        tell mainWindow
            activate
            click button "Add Source Folder"
            -- 等待文件选择弹窗加载完成
            repeat until exists sheet 1
                delay 0.1
            end repeat
            tell sheet 1
                -- 唤起路径跳转输入框
                keystroke "g" using {command down, shift down}
                -- 等待跳转输入框加载
                repeat until exists sheet 1 of it
                    delay 0.1
                end repeat
                -- 输入目标路径
                keystroke folderPosixPath
                -- 确认路径跳转
                keystroke return
                delay 0.1
                -- 如果需要直接确认选中该文件夹,保留下面这行,不需要则删除
                keystroke return
            end tell
        end tell
    end tell
end tell

注意事项

  • 不同应用的弹窗响应速度不同,你可以根据实际情况调整delay的数值避免操作失效
  • 运行脚本前需要先在「系统设置→隐私与安全性→辅助功能」中给执行脚本的工具(如脚本编辑器、Automator等)开启权限,否则GUI操作会被系统拦截
  • 如果不需要跳转后直接选中文件夹,可删除最后一行的keystroke return代码

内容的提问来源于stack exchange,提问作者userX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 13:24:03