2017-06-16 2 views
0

をファイルの名前を変更します。私はそれが名前を変更してから移動する必要があり、特定のフォルダにファイルをドロップのAppleScript/FolderAction - フォルダにドロップしたとき、私は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 

答えて

0

あなたが正しいです、ファイルの名前を変更すると、再びフォルダアクションがトリガーされます。

解決策は、順序を変更することです。最初に名前を変更して名前を変更します。

 -- 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 
関連する問題