【发布时间】:2017-06-17 11:57:40
【问题描述】:
我正在尝试使用 FolderAction 和 AppleScript 执行以下操作:
每次我将文件放到特定文件夹时,都应将其重命名,然后移至另一个文件夹。
问题是我得到了类似无限循环的东西(我认为),因为当文件被重命名时,文件夹假定文件夹中有一个新文件,依此类推。
我真的不知道如何避免这种情况并停止无限循环。这是我的脚本:
global newName
set newName to ""
on adding folder items to theAttachedFolder after receiving theNewItems
-- Get the name of the attached folder
tell application "Finder"
set theName to name of theAttachedFolder
-- Count the new items
set theCount to length of theNewItems
-- Display an alert indicating that the new items were received
activate
-- Loop through the newly detected items
repeat with anItem in theNewItems
set oldFileName to name of anItem
-- Rename the file
set the name of anItem to "NewFile" & oldFileName
-- Move the file to other folder
move anItem to "Macintosh HD:Users:blabla:blabla"
end repeat
end tell
tell application "Finder"
delete files of folder "Macintosh HD:Users:user:thisfolder
end tell
end adding folder items to
【问题讨论】:
标签: macos applescript