Image Events missing value

Hi

I had a script that worked fine until Snow lleopard

Why would i get missing value?? I have tried save this_image as JPEG in destfolder but it still does nothing


property theResize : 400
set pathto to path to home folder from user domain as string
set pathpro to "PhotoData:Process Folder"
set pathtopro to alias (pathto & pathpro)
set x to choose file
resizeiamgespot(x, theResize, pathtopro)
on resizeiamgespot(this_item, theResize, destfolder)
	tell application "Image Events"
		launch
		set this_image to open this_item
		scale this_image to size theResize
		--rotate this_image to angle -90
		save this_image in destfolder
		close this_image saving no
	end tell
end resizeiamgespot


The event log says
tell current application
path to home folder from user domain as string
→ “Whopper:Users:johnclark:”
end tell
tell application “AppleScript Editor”
choose file
→ alias “Whopper:Users:johnclark:TEMP FOLDER:5_PONA_SCA8139TEMP.JPG”
end tell
tell application “Image Events”
launch
open alias “Whopper:Users:johnclark:TEMP FOLDER:5_PONA_SCA8139TEMP.JPG”
→ image “5_PONA_SCA8139TEMP.JPG”
scale image “5_PONA_SCA8139TEMP.JPG” to size 400
save image “5_PONA_SCA8139TEMP.JPG” in alias “Whopper:Users:johnclark:PhotoData:Process folder:”
→ missing value
close image “5_PONA_SCA8139TEMP.JPG” saving no
end tell

Hi.

I haven’t tried your script, but one thing which leaps out is that you’re trying to save the image in a folder instead of a file! ‘Save’ saves documents in files, not files in folders. Some applications understand what you mean if you specify a folder as the destination, others don’t.

Hi Nigel

Your right!! Never noticed this before though all my image events handlers have worked perfectly for the last 7 years

They must have tightened the code

‘Save’ will create the file if necessary, of course, provided the folder where where you want to create it exists.


property theResize : 400
set pathto to path to home folder from user domain as string
set pathpro to "PhotoData:Process Folder:"
set pathtopro to (pathto & pathpro) -- Keep the path rather than an alias.
set x to choose file
resizeiamgespot(x, theResize, pathtopro)
on resizeiamgespot(this_item, theResize, destfolder)
	tell application "Image Events"
		launch
		set this_image to open this_item
		set file_Name to this_image's name -- Get the name of the image (same as the file it came from).
		scale this_image to size theResize
		--rotate this_image to angle -90
		save this_image in file (destfolder & file_Name) -- Save the image to a file of the same name at the destination folder.
		close this_image saving no
		quit
	end tell
end resizeiamgespot

Thanks Nigel but the script does not work.

This does though



property theResize : 400
set pathto to path to home folder from user domain as string
set pathpro to "PhotoData_Laptop:Process Folder"
set pathtopro to alias (pathto & pathpro)
set x to choose file

resizeiamgespot(x, theResize, pathtopro)
on resizeiamgespot(this_item, theResize, destfolder)
	set filename to name of (info for this_item)
	tell application "Image Events"
		launch
		set this_image to open this_item
		scale this_image to size theResize
		--rotate this_image to angle -90
		save this_image in (destfolder & filename as string)
		close this_image saving no
	end tell
end resizeiamgespot

Hello

Nigel wrote a correct instruction : save this_image in file (destfolder & file_Name)
which you copied wrongly : save this_image (destfolder & file_Name as text)

With such an error it can’t do the job :rolleyes:

Yvan KOENIG (VALLAURIS, France) mercredi 22 juin 2011 15:12:09

Hi Yvan

I ran Nigels script and it does not save the image in the desired folder

My answer was to delete Nigels way of getting the filename and include the line
set filename to name of (info for this_item)

This then processes the images and saves them with the same name in the destination folder

I repeat that the Nigel instruction use a correct syntax but yours doesn’t.

As it seems that you didn’t read carefully, I will underline your error :

In your instruction, you are asking the app to save an image in a text object : (destfolder & file_Name as text)
I must add that your concatenation will necessarily fail because in your code, destfolder is an alias and file_Name is a text item.
The correct syntax would ask the app to save in file ((destfolder as text)&file_name)

Nigel which know what is required carefully asked the app to save in the file (destfolder & file_Name)
with destfolder and file_name being text items.

Yvan KOENIG (VALLAURIS, France) mercredi 22 juin 2011 19:35:24

HI

I bow to your superior scripting talents but I have tried yours and Nigels version and they simply dont work. No file is saved to the destination folder.

My workround at least does the job. Perhaps Image Events is a bit flakey

I did test my script on my Snow Leopard machine before posting it, even setting up your folder structure in my own home folder. I don’t know why it doesn’t work for you, unless it’s because the name of one of your folders has changed since your original post. :confused:

Mmmmmmm

Typo…My apologies to you both

My wrist is slapped

Just as an aside…

When testing Image Events scripts make sure you are processing the image before saving otherwise the file is not saved

ie This produces a file at the desired location



on resizeiamgespot(this_item, theResize, destfolder)
	tell application "Image Events"
		launch
		set this_image to open this_item
		set file_Name to this_image's name 
		if theResize is 0 then
			scale this_image by factor 1
		else
			scale this_image to size theResize
		end if
		--rotate this_image to angle -90
		save this_image as JPEG in file (destfolder & file_Name) with compression level high 
		close this_image saving no
	end tell
end resizeiamgespot


This does not



tell application "Image Events"
	launch
	set this_image to open this_item
	set file_Name to this_image's name
	save this_image in file (destfolder & file_Name)
	close this_image saving no
end tell




One more time, using a wrong syntax give a wrong behavior.
If the original picture is a jpeg one, this code behaves flawlessly.

tell application "Image Events"
		launch
		set this_image to open this_item
		set file_Name to this_image's name
		save this_image as JPEG in file (destfolder & file_Name)
		close this_image saving no
	end tell

I wish to add that it’s a bit odd to use such a code to copy a file from one location to an other one :rolleyes:

Yvan KOENIG (VALLAURIS, France) jeudi 23 juin 2011 11:14:52

weedinner’s syntax isn’t actually “wrong”, since the ‘as’ parameter for Image Events’s ‘save’ command is optional. The Image Events dictionary says that the default in the absence of this parameter is to save the image in the form it already has.

It’s a common feature of Mac OS applications that you can’t save documents (here ‘images’) which haven’t been modified. That’s no doubt why weedinner’s demo script doesn’t create a new file. Presumably, the use of the ‘as’ parameter fools Image Events into thinking a change is being made and therefore allows the save to go ahead.

weedinner did in fact say it was something to watch out for while testing Image Events scripts ” which would include testing bits of them. I don’t think he meant the demo script as an end in itself. :slight_smile:

Thanks Nigel, Thats precisely what I meant. I found that whist isolating certain lines of the handler whilst testing I reached a point where the image was not created. This could leave a lot of people scratching their head thinking something else is wrong (I did).

Not all of us here are programmers or have any theoretical knowledge of scripting. I’m a photographer, not a scripter but through the help of you guys all my image and database workflows are run by applescript. Applescript was perfect for the scripting bodger. You could write quite a lot of code that was not quite right and applescript sorted it out for you. The first handler I wrote in this thread had worked flawlessly for years without me knowing that the code was flawed.
It appears that over the last few years the code has been tightened up and is therefore far less flakey than it was. For me its all part of the learning process because without applescript the way I run my current business would fail.

Hello Nigel

On my machine the original code without the as component behaved as a simple save command on the original file whose date was changed.
With the as included, the file was correctly saved at the new wanted location.

This is, from my point of view, the definition of a wrong syntax : one which doesn’t achieve what we suppose that it must do. :wink:

Yvan KOENIG (VALLAURIS, France) jeudi 23 juin 2011 14:45:09