Script not working anymore

I have the following script which last year worked fine. I have not needed it over the winter but now I come to use it again it no longer functions properly. I am assuming this is because the OS has been upgraded in the meantime. What I get now is that if a single single image lands in the parent folder it is copied and scaled correctly to the ‘Photos’ folder but if there are a batch of images, only the first image gets done. None of them in either case are now saved to ‘Thumbs’ at all.

Can anybody shed any light on this for me please.

on adding folder items to this_folder after receiving these_items
	set Photos to (this_folder as text) & "Photos"
	set Thumbs to (this_folder as text) & "Thumbs"
	
	
	repeat with aFile in these_items
		
		tell application "Image Events"
			activate
			set theImage to open aFile
			scale theImage to size 900
			save theImage as JPEG in file Photos
			
			scale theImage to size 240
			save theImage as JPEG in file Thumbs
			try
				close theImage
			on error
				delay 2
				close theImage
			end try
			
		end tell
	end repeat
	
	
	
end adding folder items to

I should add I am now running 10.7.3

I guess that this one will do the trick.


on adding folder items to this_folder after receiving these_items
	set Photos to (this_folder as text) & "Photos"
	set Thumbs to (this_folder as text) & "Thumbs"
	tell application "Finder"
		if not (exists folder Photos) then make new folder at this_folder with properties {name:"Photos"}
		if not (exists folder Thumbs) then make new folder at this_folder with properties {name:"Thumbs"}
	end tell
	repeat with aFile in these_items
		
		tell application "Image Events"
			activate
			set theImage to open aFile
			scale theImage to size 900
			save theImage as JPEG in folder Photos
			
			scale theImage to size 240
			save theImage as JPEG in folder Thumbs
			try
				close theImage
			on error
				delay 2
				close theImage
			end try
			
		end tell
	end repeat
	
end adding folder items to

At least, it does it on my 10.7.3 system. :wink:

Yvan KOENIG (VALLAURIS, France) samedi 31 mars 2012 18:06:51

Thanks Yvan but the issue is not the adding of the folders but image files to those folders and at the right scale. Interestingly it works better on my MacBook Pro but is not flawless so I am at a loss really. :confused:

HI.

It’s possibly because you’re trying to save the images to folders instead of to files within those folders. Is this any better?

on adding folder items to this_folder after receiving these_items
	set Photos to (this_folder as text) & "Photos:"
	set Thumbs to (this_folder as text) & "Thumbs:"
	
	tell application "Image Events" to launch
	
	repeat with aFile in these_items
		
		tell application "Image Events"
			set theImage to open aFile
			set imageName to theImage's name
			scale theImage to size 900
			save theImage as JPEG in file (Photos & imageName)
			
			scale theImage to size 240
			save theImage as JPEG in file (Thumbs & imageName)
			try
				close theImage
			on error
				delay 2
				close theImage
			end try
			
		end tell
	end repeat
	
	tell application "Image Events" to quit
	
end adding folder items to

Obviously it needs checks to make sure that the files dropped are image files and that the name extensions don’t need to be changed if the originals aren’t JPEGs.

Edit: Arranged for Image Events to launch (not activate, it’s a faceless app) before the repeat and to quit again afterwards.

With the script which I posted, the images are stored with the correct sizes.
For see, go to :

http://www.box.com/s/00qnssoyeq2xvc22ra4k
and download :
this_folder.zip

Yvan KOENIG (VALLAURIS, France) lundi 2 avril 2012 15:30:57

Sorry guys but neither of your kind efforts are producing any results on my machine. Is this because I have problem with AppleScript do you think. Can I install it again or is there possibly something else going on that is preventing this from working. Last year it was all fine.

Thank you both.

Ok, I spoke too soon. Yvan yours worked fine with two folders of images but now has stopped working. I have no idea why this should be but it is every frustrating.

maybe too basic questions, but

is Folder Actions enabled ?
is the script located in (~)/Library/Scripts/Folder Action Scripts ?
is an action attached to the hot folder ?
is the script assigned to the action ?

Hi Stephan

Yes folder actions is enabled.
Yes scripts are stored in correct place.

Here is how I have been using this. The first script I use has a short cut on the Dock which creates opens a text box in which I type the name of the new folder I want and at the same time creates a new Project in Aperture of the same name. The new Folder is stored as a subfolder located under ~/Events/Sites/x3a2108/current_event/ with “Events” being a username.

Attached to the folder “current_event” is another script that attaches a script, now Yvan’s, to the new folder and tell the new folders to create further subfolders called “Photos” & “Thumbs”.

So for example I create a new folder with the first script called “Junior Novice” which creates a path ~/Events/Sites/x3a2108/current_event/Junior Novice. Now Junior Novice with have subfolders of Photos & Thumbs. When ever a photo is deposited in Junior Novice it should use Yvan’s script to create the required scaled images files.

Now the ideal i when a card is put in the reader containing images, all jpg, I use Aperture to import them and store the files in the folder of the same name as the required project. The script should now kick in a create the image sizes so they display on a locally hosted website for people in my sales area to view.

I have tried to used JAlbum for this and it works but it is painfully slow. It may be that I will need to get a programmer to write some code for me to handle this instead of using script.

Now it all seems to be working like a charm. Very strange and no idea what I have done. Be interesting to see what happens after I power down and start again.