filerename triggers repeat loop

Hi all,

First of all I would like to tank everybody for all the help that I got till now. I have read many threats and found useful lines of scripts that I could insert into my project. This is actually my first project ever and it is not just a test .

But now I am a bit stuck at a point and would like to ask for any suggestion on this topic.

Description I have a folder action which controls the filename in duplicates on a server, filename length, renames the file, opens QTPlayer enters annotations, saves these, copies the file to the server and deletes the initial file in the folder.

However on the point when I tell Finder to rename the initial file the Folder Action thinks this is a new file which has just arrived and launches the script again. But in this moment the file has already been deleted from the folder and the script ends with an error “QT Player is unable to open file”.

Up to now I have not found a way to stop the folder action from starting after the rename of the file.
Counting the number of files did not work. (at least the way I did it)

Does anyone had such an issue arready and could give me an idea? This would be welcomed, thanks.

It seems that:

  1. You’d better include your scripting, as we now need to guess what happens out there.
  2. My best guess is that what triggers your script, gets triggered by the event that your script produces. Critically review what handler you use and what outcome ir produces for Finder (/folders).

Hi,

Well indeed it is a bit complicate without script. As it is rather long, I extracted the parts that does not work, or better runs twice.
So after the step --set newFilename to filenamex the script detects the rename as beeing a new file and restarts running from the beginning.

Here the script, thanks for any sugestion.



on adding folder items to this_folder after receiving theseItems
	
	
	repeat with currentItem in theseItems
		
		
		
		set F to quoted form of POSIX path of currentItem
		set sizeThen to first word of (do shell script "du -d 0 " & F) as integer --coercing to integer fixes the quote problem
		repeat
			try
				delay 2 -- seconds (set to longer if needed)
				set sizeNow to first word of (do shell script "du -d 0 " & F) as integer --coercing to integer fixes the quote problem
				if sizeNow - sizeThen = 0 then exit repeat
				set sizeThen to sizeNow
			on error
				exit repeat
			end try
			
		end repeat
		
		
		
		
		tell application "Finder"
			if name of currentItem is not "" then
				set filename to name of currentItem
			end if
			set thePath to the currentItem as string
			
			if not (exists currentItem) then exit repeat
			
			
			
			------- temp config
			
			--configuration preferences for test mode
			set VolumeDestin to "D"
			set serverDestin to "smb://login@Server/D"
			set serverFolder to "TEST"
			set serverPath to "D:Server:TEST"

			
			set maxlength to 8 --Clip ID length
			
			------------------------------
			
			if filename contains "." then
				set AppleScript's text item delimiters to {"."}
				set extn to text item -1 of filename
				set filenamex to text item -2 of filename
				set AppleScript's text item delimiters to {""}
			else
				set filenamex to filename
				set extn to 0
			end if
			
			set newFilename to filenamex
			set tempFilename to length of (newFilename)
			
			
			if (not (exists disk VolumeDestin)) then
				set mountString to serverDestin
				mount volume mountString
				set remoteVolumeName to name of (info for (mount volume serverDestin))
			end if
			
			----------------------------------------------------------
			--name rename handler
			--check whether the filename exisits and if name length is correct
			
			--set filename to UPPERCASE only
			-------------
			
						
			set newFilename to new_text
			
			-------------
			--alter file extention
			if extn = ".mov" then
				set newextn to extn
			else
				set newextn to ".mov"
			end if
			
			tell application "Finder" to set name of currentItem to newFilename & newextn
			set extension hidden of currentItem to false
			
			
			delay 1
			
			set thePath to the currentItem as string

		end tell
		
		
		--display dialog nameIT
		try

			if not (exists thePath) then
				exit repeat

				
			else
				
				tell application "QuickTime Player"
					activate
					
					try
						open file thePath
						delay 1
						
											
						tell movie 1
							
							--Quicktime handler here
							------------------------------------------------------------------------------------
														
							--saves the changes and closes the project
							save
							close
							quit application
							
						end tell

						---------------------
					
						tell application "Finder"
							
							move file currentItem to serverPath 							
							------------------	
							set F to quoted form of POSIX path of currentItem
							set sizeThen to first word of (do shell script "du -d 0 " & F) as integer --coercing to integer fixes the quote problem
							
							repeat
								try
									delay 1 -- seconds (set to longer if needed)
									set sizeNow to first word of (do shell script "du -d 0 " & F) as integer --coercing to integer fixes the quote problem
									if sizeNow - sizeThen = 0 then exit repeat
									set sizeThen to sizeNow
								on error
									exit repeat
								end try
							end repeat
							
							delay 3
							
						end tell

						----------------
						
					on error error_message number error_number
						if the error_number is not -128 then 
							beep
							display dialog error_message buttons {"Cancel"} default button 1
						end if
						----------------
					end try
				end tell
			end if
		end try
	end repeat
	tell application "Finder"
		delete file currentItem
		delay 3
	end tell
	
end adding folder items to

Your script goes between the AppleScript tags – I’ve done that to your post. Adam

That is the shortcoming of Folder Actions: they trigger on changes to the folder content, such as a new name appearing. The cure is to move the file first, and then have the folder action script rename it in its new location and do what ever other processing is required there. If you are moving a file to a different volume (like a server or another disk partion) then AppleScript won’t move it, it duplicates it. To get it out of the action folder, you then have to delete it. Deletions will not trigger “on adding items to…” so the folder action won’t trigger.

Thanks Adam, If your proposal with a different folder is the only cure to a filerename, I will have to try this.
Thanks for the script adding into the quotes.
Actually I do a duplicate of the file to the server and a delete right after. This part works fine.