Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

registudio

macrumors member
Original poster
Aug 8, 2013
71
2
Montreal, QC
Hi Guys,

First things first I'm a beginner and I'm trying my first script to count periodically (lets say every 5min) a number of files in a selected folder to move them after to another destination when the appropriate known number is reached.

However, for now I'm stuck to the moving files process for some reason.
I'm sure I have missed something somewhere but I can't figure it at all ;o(

Next will be to set the cycling checking event, well any clue would be appreciated.

Here is my start:

Code:
display dialog "How many render frames will you have?" default answer ""
set numberResponse to text returned of result
set renderFolder to choose folder with prompt "Please select directory."
tell application "System Events"
	set item_list to POSIX path of every disk item of renderFolder
end tell
tell application "Finder"
	set NoOfFiles to the number of items in item_list
	if NoOfFiles = numberResponse then move entire contents of folder "Macintosh HD:Users:grace:Downloads:Regis:source" to "Macintosh HD:Users:grace:Desktop:destination"
end tell

Thank you
:)
 
No coercion is done with equality and inequality tests so the comparison 5 = "5" is false. You need to coerce your numberResponse into an integer. You can do something like this :

Code:
set validNumber to false

repeat while not validNumber
	display dialog "How many render frames will you have?" default answer "Only Enter Integers"
	try
		set numberResponse to text returned of result [B]as integer[/B]
		
		set validNumber to true
	end try
	
	if not validNumber then
		display dialog "You didn't enter an integer" with icon caution
	end if
end repeat


set renderFolder to choose folder with prompt "Please select directory."

tell application "System Events"
	set item_list to POSIX path of every disk item of renderFolder
end tell

tell application "Finder"
	set NoOfFiles to the number of items in item_list
	if NoOfFiles = numberResponse then move entire contents of folder "Macintosh HD:Users:grace:Downloads:Regis:source" to "Macintosh HD:Users:grace:Desktop:destination"
end tell

Also be aware that your item_list contains a hidden .DS_Store item which will mess up your NoOfFiles count.
Use this to only list visible disk items :

Code:
tell application "System Events"
	set item_list to POSIX path of every disk item of renderFolder [B]whose visible is true[/B]
end tell
 
Last edited:
No coercion is done with equality and inequality tests so the comparison 5 = "5" is false. You need to coerce your numberResponse into an integer. You can do something like this :

Code:
set validNumber to false

repeat while not validNumber
	display dialog "How many render frames will you have?" default answer "Only Enter Integers"
	try
		set numberResponse to text returned of result [B]as integer[/B]
		
		set validNumber to true
	end try
	
	if not validNumber then
		display dialog "You didn't enter an integer" with icon caution
	end if
end repeat


set renderFolder to choose folder with prompt "Please select directory."

tell application "System Events"
	set item_list to POSIX path of every disk item of renderFolder
end tell

tell application "Finder"
	set NoOfFiles to the number of items in item_list
	if NoOfFiles = numberResponse then move entire contents of folder "Macintosh HD:Users:grace:Downloads:Regis:source" to "Macintosh HD:Users:grace:Desktop:destination"
end tell

Also be aware that your item_list contains a hidden .DS_Store item which will mess up your NoOfFiles count.
Use this to only list visible disk items :

Code:
tell application "System Events"
	set item_list to POSIX path of every disk item of renderFolder [B]whose visible is true[/B]
end tell


Thank you for your help.
Yep I noticed the .DS file that's why I've added in my last version +1 to numberResponse.
I also started to play with delay for the cycling.

Cheers
Regis
 
@kryten2
All set and running smoothly with notification and email sent at the end.
I did use my own code but yours was very very helpful to point me the mistakes I made.

Thank you

Cheers
Regis
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.