简体   繁体   中英

Applescript not delaying in Automator

I'm trying to create a scanner script. It's working in Script Editor, but in Automator the delay is not working. The function executes immediately instead.

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

Any ideas why this isn't working?

You should've posted your Workflow as well, because that's the problem. Your script does not return a value, so the following action after this Run Script action does not wait for a returned value before moving on to the next action. One solution to try is make the next action dependent on receiving a value from the previous script action. Also, this convoluted way of checking to verify that "Image Capture" is running is unnecessary. I would suggest:

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

Also, I'm not sure your GUI Scripting reference will work in all situations, but that's another issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM