Macos AppleScript/FolderAction-将文件放入文件夹时重命名>;无止境的循环

Macos AppleScript/FolderAction-将文件放入文件夹时重命名>;无止境的循环,macos,applescript,Macos,Applescript,我正在尝试使用FolderAction和AppleScript执行以下操作: 每次我将一个文件放到一个特定的文件夹中,它都应该被重命名,然后移动到另一个文件夹中。 问题是我得到了一个类似于无限循环的东西(我认为),因为当文件被重命名时,文件夹假设文件夹中有一个新文件,依此类推 我真的不知道如何避免这种情况,停止这种无休止的循环。这是我的剧本: global newName set newName to "" on adding folder items to theAttachedFolder

我正在尝试使用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

没错,重命名文件会再次触发文件夹操作

解决方案是更改顺序:先移动,然后重命名

        -- Move the file to other folder
        set movedItem to move anItem to "Macintosh HD:Users:blabla:blabla"

       -- Rename the file
        set the name of movedItem to "NewFile" & oldFileName