Folder Actions - Filter File by Dimensions

Hello everyone, I’ve been trying to create a Folder Action Script that does the following:

  • waits until the file has been transferred over to folder.
  • checks the “natural dimensions” of the movie file.
  • based on the dimensions of file (ex. 1920x1080 - 720x480), it will duplicate file to a specific folder.

The if/else statement will work on its own, however, when I include it as part of the “on adding folder items” script, it does not work

Here is what I have so far:

on adding folder items to thisFolder after receiving theItems

repeat with f in theItems
	
	set Was to 0
	
	set isNow to 1
	
	repeat while isNow ≠ Was
		
		
		tell application "System Events" to set Was to size of f
		
		
		delay 5
		
		tell application "System Events" to set isNow to size of f
		
		
	end repeat
	
	tell application "Finder"
		tell application "System Events"
			set mov_dem to natural dimensions of movie file f
			if mov_dem is {0, 0, 1920.0, 1080.0} then					
                            tell application "Finder" to duplicate f to folder "HD files" of folder "SVR" of disk "MEDIA" with replacing
				
			else if mov_dem is {0, 0, 720.0, 486.0} then					
                    tell application "Finder" to duplicate f to folder "SD files" of folder "SVR" of disk "MEDIA" with replacing
		end if
		end tell
	end tell
end repeat

end adding folder items to

You may try to use :

on adding folder items to thisFolder after receiving theItems
	
	repeat with f in theItems
		# f is an alias
		set Was to 0
		
		set isNow to 1
		
		repeat while isNow ≠ Was
			
			# System Events is able to get the size of a file defined as an alias
			tell application "System Events" to set Was to size of f
			
			delay 5
			# System Events is able to get the size of a file defined as an alias
			tell application "System Events" to set isNow to size of f
			
		end repeat
		
		# tell application "Finder"
		tell application "System Events"
			# System Events is unable to get the natural dimensions of a file defined by an alias
			# So, coerce the alias into a string
			set mov_dem to natural dimensions of movie file (f as text)
			# No need to continue to speak to System Events, we no longer use it
		end tell # System Events
		# At least under Yosemite, the four values returned are integer ones. So we must compare them to integers
		if mov_dem is {0, 0, 1920, 1080} then
			tell application "Finder" to duplicate f to folder "MEDIA:SVR:HD files:" with replacing
			
		else if mov_dem is {0, 0, 720, 486} then
			tell application "Finder" to duplicate f to folder "MEDIA:SVR:SD files:" with replacing
		end if # mov_dem .
		# end tell
	end repeat
	
end adding folder items to

Read carefully the embedded comments.

Yvan KOENIG (VALLAURIS, France) vendredi 21 novembre 2014 21:27:25

Script is working!

Thanks again Yvan. Really appreciate your help.

Cheers, C