applescript - 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.
解决方案
我想到了。上面的响应通过编写以不同顺序发生的事件将我带到那里。我还将 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
推荐阅读
- javascript - 如何使用 officejs api 在 MS Word 中重新加载页眉和页脚
- python-3.x - 如何使用 IQR 从 DataFrame 中删除异常值?
- java - java代码为什么println 10?
- css - flex-direction:Safari 中的列
- reactjs - React PropType 检查动态对象
- javascript - 在动态生成的 div 上应用 touchstart
- scala - Scala 中 DSE Cassandra 上的 Spark SQL 查询
- ember.js - 如何减少 Windows 10 上的 ember 应用程序构建时间,但它在 ubuntu 上运行良好
- sql - Why doesn't cross join work in my query?
- javascript - 函数式编程多态性