2 Replies Latest reply: Aug 7, 2013 2:48 AM by @netjjordan
Bobby Dazzler Level 1 Level 1 (0 points)
I have set up a folder action that adds a suffix (_HR) to pdf files that are dropped into it but the problem is it keeps repeating the action on the same file so you end up with filenameHR_HRHR.pdf

How do you stop the action repeating on files it has already processed?

MacPro 2.93 Ghz Quad, Mac OS X (10.5.7)
  • red_menace Level 6 Level 6 (14,785 points)
    Renaming an item inside of the attached folder will trigger the folder action again, the same as adding a new item.

    You can move the item out of the attached folder before renaming it. Since folder actions are specific to a folder, you could also keep a folder inside of your attached folder and use that.
  • @netjjordan Level 1 Level 1 (0 points)

    Or you could code a little trap in the script to not process files with a given suffix. Here's one of mine which tests for the suffix "_crtolf"

     

     

     

    -- Script to translate CR to LF as a folder action

    -- Julian Jordan 06/08/2013

     

     

    on adding folder items to this_folder after receiving added_items

     

              try

     

                        repeat with i from 1 to number of items in added_items

                                  tell application "Finder"

                                            set this_item to item i of added_items

                                            set the item_info to the info for this_item

                                            set the the_file_name to the name of this_item

     

     

                                            set the folder_name to the name of this_folder

                                            set nameExt to name extension of (item i of added_items)

                                            set oldName to text -((count nameExt) + 8) through -((count nameExt) + 2) of (get name of (item i of added_items))

     

                                            --Don't process new file we've just made - otherwise endless loop

                                            if (oldName ≠ "_crtolf") then

                                                      set theUnixPath to POSIX path of (item i of added_items)

                                                      set theShellString to "tr '\\r' '\\n' < " & quoted form of (theUnixPath) & " > " & quoted form of (theUnixPath & "_crtolf.txt")

                                                      do shell script theShellString

                                            end if

     

                                  end tell

                        end repeat

     

              end try

     

     

    end adding folder items to