Applescript不会在Automator中延迟

时间:2014-09-21 22:21:26

标签: macos applescript automator

我正在尝试创建扫描程序脚本。它在脚本编辑器中工作,但在Automator中,延迟不起作用。该函数立即执行。

on imageCaptureOpen()
    tell application "System Events" to (name of processes) contains "Image Capture"
end imageCaptureOpen

on scanImage()
    tell application "System Events"
        tell process "Image Capture"

            set scanWindow to group 2 of splitter group 1 of window 1

            set comboBox to combo box 1 of scroll area 1 of scanWindow
            if value of comboBox as number is less than 300 then set value of comboBox to "300"

            if button "Scan" of scanWindow exists then click button "Scan" of scanWindow

        end tell
    end tell
end scanImage

if not imageCaptureOpen() then
    tell application "Image Capture" to activate
    delay 30
    scanImage()
else
    scanImage()
end if

为什么这不起作用?

1 个答案:

答案 0 :(得分:0)

你也应该发布你的工作流程,因为这就是问题所在。您的脚本不返回值,因此执行此脚本操作后的以下操作不会等待返回的值,然后再继续执行下一个操作。尝试的一个解决方案是使下一个操作依赖于从前一个脚本操作接收值。 此外,这种复杂的检查方式验证“图像捕获”正在运行是不必要的。我建议:

tell application "Image Capture" to activate
tell application "System Events"
    tell process "Image Capture"

        set scanWindow to group 2 of splitter group 1 of window 1
        set comboBox to combo box 1 of scroll area 1 of scanWindow
        if value of comboBox as number is less than 300 then set value of comboBox to "300"     
        if button "Scan" of scanWindow exists then click button "Scan" of scanWindow    
    end tell
end tell

另外,我不确定您的GUI脚本参考是否适用于所有情况,但这是另一个问题。