Applescript Issue with Temp files

I am trying to solve an issue with a renaming script, that needs to wait for a file to complete before the renaming process begins.

I am trying to do this by monitoring the files size. But i am having issues, as at the moment the script is just monitoring the file twice. Any help much appreciated!

from a struggling applescript newbie!

set watchFolder to choose folder with prompt "Select folder where you will drop the video files that are to be renamed.The folder must be empty."
set destinationFolder to choose folder with prompt "Select target folder for renamed video."

set theName to "test" -- the baseName
set n to 1 -- the starting number
set theExt to ".mov" -- name extension

repeat until n > 17
	
	tell application "System Events"
		
		repeat with i in (get files of watchFolder whose name ends with theExt)
			
			set Size_1 to size of (files of watchFolder whose name ends with theExt)
			delay 3
			set Size_2 to size of (files of watchFolder whose name ends with theExt)
			repeat until Size_2 = Size_1 -- repeat while sizes are different
				
				delay 3 -- wait three seconds					
				
			end repeat
			
			move i to destinationFolder
			set name of the result to theName & n & theExt
			set n to n + 1
		end repeat
		
	end tell
	
	delay 1
end repeat

on quit
	display dialog "Really quit?" buttons {"No", "Quit"} default button "Quit"
	if the button returned of the result is "Quit" then
		tell application "System Events"
			keystroke "." using command down
		end tell
		continue quit
	end if -- If I don't continue the quit, the app will keep running.
end quit


Model: MacBook Pro
AppleScript: 2.3
Browser: Safari 534.58.2
Operating System: Mac OS X (10.6)

Hello and welcome to Macscripter! :slight_smile:

I have tried to make your script work better, but I haven’t tested it. I did drop the loop for only treating the first 17 files before quitting. I think I have made the script both more precise, and efficient, by only dealing with the currentFile, in the set of files that ends with ext. Furthermore, I removed the keypress command “.” as that isn’t necessary, a continue quit suffices!

All in all, I hope the script works, and please come back if there is any unforeseen side-effects! One sideffect may very well be that the file needs some time to be moved to the destination folder, but I am a little bit unsure of that, I know to much I guess. :slight_smile: If the file are moved the unix way, then the entry of the directory is just removed, after a new link to the same file is created in the destination directory.

set watchFolder to choose folder with prompt "Select folder where you will drop the video files that are to be renamed.The folder must be empty."
set destinationFolder to choose folder with prompt "Select target folder for renamed video."

set theName to "test" -- the baseName
set n to 0 -- the starting number
set theExt to ".mov" -- name extension


tell application "System Events"
	
	repeat with currentFile in (get files of watchFolder whose name ends with theExt)
		set n to n + 1
		set Size_1 to size of currentFile
		delay 3
		set Size_2 to size of currentFile
		repeat until Size_2 = Size_1 -- repeat while sizes are different
			
			delay 3 -- wait three seconds					
			
		end repeat
		
		move currentFile to destinationFolder
		set name of the result to theName & n & theExt
	end repeat
	
end tell

on quit
	display dialog "Really quit?" buttons {"No", "Quit"} default button "Quit"
	if the button returned of the result is "Quit" then
		continue quit
	end if -- If I don't continue the quit, the app will keep running.
end quit

Hi, thanks for the help. that doesn’t see to be working though, and in fact it locks up the Applescript maker :frowning:

i have the loop until n > 17 as i want the script to stop when i have reached n = 16.

also n needs to start at 1 for the program that is searching for the renamed files.

the way i had it, the renaming was working, but the file size checking was not :frowning: and the script was still taking the file as soon as it appeared.

Hi,

this repeat loop


repeat until Size_2 = Size_1 -- repeat while sizes are different
           delay 3 -- wait three seconds                       
end repeat

cannot work, because Size 1 and 2 aren’t updated automatically.
You have to write something like this


.
set theExt to "mov" -- name extension

repeat until n > 17
	
	tell application "System Events"
		
		repeat with aFile in (get files of watchFolder whose name extension is theExt)
			repeat
				set Size_1 to size of aFile
				delay 3
				set Size_2 to size of aFile
				if Size_2 = Size_1 then exit repeat
			end repeat
			
			move aFile to destinationFolder
			set name of the result to theName & n & "." & theExt
			set n to n + 1
		end repeat
		
	end tell
	
	delay 1
end repeat
.

Thanks Stefan.

I am almost blushing, I have no idea how I managed to overlook that. I think I just assumed it was all right.

StefanK thankyou! your script didn’t work, but the proper if statement rules did, when i implemented them into my own script! thankyou so much! i Hope the good karma comes back two fold :slight_smile:

in the end this is now the working script…

if anyone was interested, it is for a Sonic Arts project that needs to rename Skype calls as they are recorded on the fly, and then projected into a video mix patch done in Max/MSP. This applescript will now mean that the project is a success - and hence my PhD can continue :slight_smile:

thankyou again to all!

set watchFolder to choose folder with prompt "Select folder where you will drop the video files that are to be renamed.The folder must be empty."
set destinationFolder to choose folder with prompt "Select target folder for renamed video."

set theName to "test" -- the baseName
set n to 1 -- the starting number
set theExt to ".mov" -- name extension

repeat until n > 17
	
	tell application "System Events"
		
		repeat with i in (get files of watchFolder whose name ends with theExt)
			repeat
				set Size_1 to size of (files of watchFolder whose name ends with theExt)
				delay 3
				set Size_2 to size of (files of watchFolder whose name ends with theExt)
				if Size_2 = Size_1 then exit repeat -- repeat while sizes are different
			end repeat
			
			move i to destinationFolder
			set name of the result to theName & n & theExt
			set n to n + 1
		end repeat
		
	end tell
	
	delay 1
end repeat

on quit
	display dialog "Really quit?" buttons {"No", "Quit"} default button "Quit"
	if the button returned of the result is "Quit" then
		tell application "System Events"
			keystroke "." using command down
		end tell
		continue quit
	end if -- If I don't continue the quit, the app will keep running.
end quit