Moving files

Hi
With my script (below), I want to move a file after it’s been emailed.I created a script that works on its own but when I tried it in my main script it said that the file_path variable was un defined;

property default_address : “someone@somewhere.com
property mail_subject : “Client name”
set file_path to “Macintosh HD:Users:username:Desktop:testmove:”
global attachment_name
tell application “Finder”
end tell
on open the_files
set attachment_name to name of (info for (the_files’s item 1))
set mail_subject to text returned of (display dialog "Enter client name for " & attachment_name default answer “Client name”)

tell me to activate
set the compression_setting to "No"
tell application "Microsoft Entourage"
	activate
	set MyMessage to make new draft window with properties ¬
		{recipient:default_address, subject:attachment_name & " - " & mail_subject, attachment:the_files}
	if class of window 1 is draft news window or class of window 1 is draft window then
		tell window 1
			try
				set theNames to name of every attachment
			on error
				return -99 -- silent exit
			end try
			if (count theNames) > 1 then
				set messageText to ""
				repeat with aName in theNames
					set messageText to messageText & return & tab & aName
				end repeat
				set messageText to messageText & return & return
			else if (count theNames) = 1 then
				set messageText to return & theNames & return & return
			end if
			set selection to messageText
		end tell
	end if
	send MyMessage
end tell
tell application "Finder"
	move file_path & attachment_name to desktop replacing yes
	activate

end tell
end open

You have two handlers: one of them “implicit” (on run); the other “explicit” (on open).
You define file_path in “on run”. That’s because your other handler (on open), the one which manipulates the variable file_path doesn’t know about the existence of it… That’s what we call “scope” of variables. If you wish a variable to be available for all elements in the script, you must declare it as global or property. If you don’t, these will be variables of type local and they will only be accessible within the current handler.
So, to make it work, you must apply just the same method you used for your variable attachment_name

OK, I follow what you mean but am not sure how to implement it. What I have done is added the global in here;

property default_address : “someone@somewhere.com
property mail_subject : “Client name”
global attachment_name
global file_path

and then added

tell application “Finder”
set file_path to “Macintosh HD:Users:username:Desktop:testmove:”
move file_path & attachment_name to desktop replacing yes
activate
end tell

and get an error of;
“Handler can’t handle objects of this class”

This works for me (AS 1.9.1, OS 10.2.4, Finder 10.2.1):

global file_path
global attachment_name

set file_path to "Macintosh HD:Users:username:Desktop:testmove:"
set attachment_name to "file to move to desktop"

tell application "Finder"
	move file_path & attachment_name to desktop replacing yes
end tell

Sorry, I’m getting a bit confused.

these two have been defined a global at the beginning of the script - that’s fine

I’ve defined the path to the folder that the file is being moved from

This is where I’m getting confused - I take it that you want me to substitue the text in the quotes to the name of the file, however, haven’t we already defined this variable earlier on as
set attachment_name to name of (info for (the_files’s item 1)
This is the right file name and the file I want to move so why are we redefining it?