Capture One 21文件夹监控自动化脚本问题求助
Capture One 21 联机拍摄自动化问题解决
需求概述
监控桌面名为「Hochzeit Teather Ordner」的联机拍摄文件夹,当有新文件添加时,触发Capture One 21的Command+D快捷键,将RAW文件导出为JPG到指定文件夹。
已完成工作
- 配置Automator工作流监控目标文件夹,包含Shell脚本检测新文件并触发AppleScript发送快捷键
- 编写Shell脚本实现保存文件夹文件列表、定期检查更新,检测到新文件时调用AppleScript模拟快捷键
- 编写AppleScript用于发送
Command+D快捷键,但始终出现语法错误:end expected, but on found
遇到的问题
- AppleScript反复出现「end expected, but on found」语法错误
- 已配置Automator和System Events的按键发送权限,但问题仍存在
- 整个工作流无法正常执行
当前脚本
Shell脚本
#!/bin/bash captureFolder="$1"tempFile="/tmp/current_files.txt" # 保存初始文件列表 ls "$captureFolder" > "$tempFile" # 新文件监控循环 while true; do sleep 10 currentFiles=$(ls "$captureFolder") if ! diff <(echo "$currentFiles") "$tempFile" > /dev/null; then osascript -e 'tell application "System Events" to keystroke "d" using {command down}' ls "$captureFolder" > "$tempFile" fi done
报错的AppleScript
on run {input, parameters} -- Pfad zum Capture One-Ordner set captureFolderPath to POSIX path of (item 1 of input) -- Helper function to retrieve the file names in the folder -- on listFilesInFolder(folderPath) -- set fileList to do shell script "ls " & quoted form of folderPath -- return fileList -- end listFilesInFolder -- Save initial file list set currentFiles to listFilesInFolder(captureFolderPath) -- New file monitoring loop repeat delay 10 -- Warte 10 Sekunden -- Get new file list set newFiles to listFilesInFolder(captureFolderPath) -- Check if the file list has changed if currentFiles ≠ newFiles then -- Wenn sich die Dateiliste geändert hat, sende Tastenkombination an Capture One tell application "System Events" tell process "Capture One 21" -- Ersetze "Capture One 21" durch die Version, die du verwendest if exists window 1 then keystroke "d" using {command down} end if end tell end tell -- Update the list of current files set currentFiles to newFiles end if end repeat return input end run
解决方案
1. AppleScript语法错误修复
报错原因是注释掉了listFilesInFolder函数但仍调用该未定义函数,同时注释格式不规范。修复后的脚本完全兼容Automator工作流:
on run {input, parameters} -- 获取传入的文件夹路径 set captureFolderPath to POSIX path of (item 1 of input) -- 定义文件列表获取函数 on listFilesInFolder(folderPath) set fileList to do shell script "ls " & quoted form of folderPath return fileList end listFilesInFolder -- 保存初始文件列表 set currentFiles to listFilesInFolder(captureFolderPath) -- 监控循环 repeat delay 10 -- 获取最新文件列表 set newFiles to listFilesInFolder(captureFolderPath) -- 检测文件变化 if currentFiles ≠ newFiles then -- 激活Capture One确保快捷键生效 tell application "Capture One 21" activate end tell tell application "System Events" tell process "Capture One 21" keystroke "d" using {command down} end tell end tell -- 更新文件列表 set currentFiles to newFiles end if end repeat return input end run
2. 替代方案建议
方案一:Capture One内置自动导出(最优)
Capture One原生支持联机拍摄自动导出,无需编写脚本:
- 打开Capture One进入「联机拍摄」模式
- 进入「联机拍摄设置」,找到「自动导出」选项
- 设置导出格式为JPG,指定目标文件夹,勾选「检测到新文件时自动导出」
方案二:用Folder Action替代Automator
Folder Action是macOS原生轻量文件夹监控工具,比Automator更稳定:
- 打开「自动操作」,新建「文件夹操作」
- 选择目标文件夹「Hochzeit Teather Ordner」
- 添加「运行AppleScript」动作,使用以下脚本:
on adding folder items to this_folder after receiving added_items tell application "Capture One 21" activate end tell tell application "System Events" tell process "Capture One 21" keystroke "d" using {command down} end tell end tell end adding folder items to
3. 权限设置细节
必须开启以下权限(路径:系统设置 > 隐私与安全性):
- 辅助功能:勾选「自动操作」「终端」「System Events」「Capture One 21」
- 文件与文件夹:给「自动操作」「终端」授予对「Hochzeit Teather Ordner」的访问权限
内容的提问来源于stack exchange,提问作者Christian Rückert
相关产品推荐
相关产品推荐

