newb move question

what i’m trying to do is write a script that lets me move a certain file from a folder to another folder. i’m running my script via a perl script using the osa command so i can pass it parameters. i’m passing, file_name, source_folder, and dest_folder. this is a simplified version of my code:

on run param_list

	set file_name to item 1 of param_list
	set source_folder to item 2 of param_list
	set dest_folder to item 3 of param_list

	tell application "Finder"
		move file file_name of source_folder to dest_folder
	end tell

end run

i am passing something like “harddrive:folder:folder:” as the paths.
i’ve tried many differnet variations including something like this:

on run param_list

	set file_name to item 1 of param_list
	set source_folder_string to item 2 of param_list as string
	set dest_folder_string to item 3 of param_list as string

	tell application "Finder"
		set source_folder to folder source_folder_string 
		set dest_folder to folder dest_folder_string 
		move file file_name of source_folder to dest_folder
	end tell

end run

i know there’s a simple answer to this, something to do with sting types or folder types and what they can be passed to. anyone have any ideas?

Hi,

Your source_folder and dest_folder are strings, but you need references:

set param_list to ¬
{“the file”, “Macintosh HD:Users:kel:Desktop:source:”, “Macintosh HD:Users:kel:Desktop:dest:”}
– notice that param_list contains items of class string
tell param_list
set file_name to (item 1)
set source_folder to (item 2) as alias
set dest_folder to (item 3) as alias
end tell
tell application “Finder”
move file file_name of source_folder to dest_folder
end tell

In the tell param_list block (item 2) is a string and it is coerced to alias reference. The same goes for dest_folder. You can’t do this with (item 1) because it is just a name and not a path. If you try to coerce the file name to ‘alias’ it would error because it would look for a disk by that name. The ‘tell param_list’ block is used so you don’t need to keep typing ‘of param_list’ three times.

In the Finder tell block:

move file file_name of source_folder …

this is a mixed reference. It uses both finder reference and alias reference in one. Again, while your posted script used strings with the ‘move’ command, my script uses alias references.

gl,

Hi,

I would probably do it like this:

set param_list to ¬
{“the file”, “Macintosh HD:Users:kel:Desktop:source:”, “Macintosh HD:Users:kel:Desktop:dest:”}
– notice that param_list contains items of class string
set {file_name, source_folder_path, dest_folder_path} to param_list
set file_reference to (source_folder_path & file_name) as alias
set dest_reference to dest_folder_path as alias
tell application “Finder”
move file_reference to dest_reference
end tell

because I like to give the Finder all the help I can. As you can see there are many ways to do this. Coercing to alias is good because it will error if the item does not exist and you can trap the error. Also, alias reference may be used troughout the script even if the name or location of the item changes within the script execution.

gl,

cool, got it working, thanks!