Why can´t my script remember...

Hi folks,

This is a small sample of my script problem. Properbly is it a very simple to solv, but I don´t know where or what I willl search for…
So, it seems that my script can´t remember the “TheImage” information when it goes to “sub1”-section.

The script isn´t so long, so the computer should remember it…ehhh.

Thanks mates.

//BigS

Todays wishdom
– Money doesn´t make people happy. I´m not happier now with 150 millions than with 80.
– Arnold Schwarzenegger


tell application "Finder"
	set TheImage to choose file
	my sub1()
	
end tell

on sub1()
	tell application "Image Events"
		run
		open TheImage
	end tell
end sub1

Swede:

This should be a simple fix. Whenever you call a subroutine (often called a handler in Applescript), you need to send the variable you want with it, otherwise, yes, the script is stupid. There are two methods:


tell application "Finder"
	set TheImage to choose file
	my sub1(TheImage)--Here is the variable you want sent to the sub
	
end tell

on sub1(a)--You can use any other variable name you want to recieve the original variable..
	tell application "Image Events"
		run
		open a--..so long as you remember to use that variable later on.
	end tell
end sub1

The second way (which is considered less cool) is to make the variable global in nature, so that every tell block or every subroutine/handler can use the value in that variable:

global TheImage
tell application "Finder"
	set TheImage to choose file
	my sub1(TheImage)
	
end tell

on sub1(TheImage)
	tell application "Image Events"
		run
		open TheImage
	end tell
end sub1

If you seriously plan on using Image Events, take a look at Apple’s website for scripting that application. Here is the link, for your convenience, which can be found at our MacScripter Links page (http://macscripter.net/links/)

http://www.apple.com/applescript/imageevents/index.html

There are also some good threads on our bbs here about that application, so search for those if you think it will help.

Good luck, stop back if you need any more information.

Nice. That works.
You guys are incredible.
Special thanks to you, Craig.

By the way. I going to use PS CS2 in my final script, because the script must be able to handle regular images, pdf´s and EPSF.

Take care, friends.

//BigS