首页 > 解决方案 > How to use if/else combined with Automator Loop

问题描述

I've automated the processing of a logo but need to make it possible to process a variable number of logos. I've achieved this with nested applescript in an automator workflow, but the loop does not perform the entire script.

Logos are passed to Incoming folder, the workflow/script changes the desktop to indicate the system is active, grabs the first file, then continues formatting and distributing the file via automator actions. At the end a Loop returns to the beginning until the Incoming folder is empty.

set FileAlias to (POSIX file "/Incoming") as alias

tell application "Finder"
    count files of entire contents of FileAlias
    if the result is 0 then

        quit application "_Logos"

        launch application "Reset_Desktop"
    else

        move first item of FileAlias to (POSIX file "/Scripts")

    end if
end tell

As you'll see in the script, I'm asking the process to stop if the Incoming folder is empty. This works, but the additional step of resetting the desktop fails to happen. Though if I run the process with no files in the folder to begin with, the desktop does reset.

标签: applescriptautomator

解决方案


我想到了。上面的响应通过编写以不同顺序发生的事件将我带到那里。我还将 Applescript 一分为二;一个出现在工作流的开始,另一个出现在最后,就在循环操作之前。

第一个Applescript:

    set FileAlias to (POSIX file "/Incoming") as alias   
    tell application "Finder"
        count files of entire contents of FileAlias
        if the result is 0 then
            null
        else
        move first item of FileAlias to (POSIX file "/Scripts") 
    end if
end tell

第二个Applescript:

set FileAlias to (POSIX file "/Incoming") as alias    
tell application "Finder"       
    count files of entire contents of FileAlias
    if the result is 0 then         
        launch application "Reset_Desktop"
        quit application "Logos"        
    end if      
end tell

推荐阅读