PDA

View Full Version : AppleScript: Moving a file


HermXIV
11-17-2009, 10:30 PM
I feel really stupid asking this, as it is such a simple process, but I have been mulling over this at least an hour and can't figure it out. The problem is I want the user to select a file via the choose file command. Then select a folder via the choose folder command. After that I want to move the selected file to the selected folder. For some reason I can't get this to work. Here is what I have. Help please?

set the_file to (choose file) as string
set the_folder to (choose folder) as string
tell application "Finder"
move the_file to the_folder
end tell

ganbustein
11-18-2009, 01:20 AM
The problem is that you're telling Finder to move one string to another string. It has no idea how to do that. It does know how to move a file to a folder.

Either leave off the "as string" modifiers:
set the_file to (choose file)
set the_folder to (choose folder)
tell application "Finder"
move the_file to the_folder
end tell
or cast the strings back to, respectively, a file and a folder:
set the_file to (choose file) as string
set the_folder to (choose folder) as string
tell application "Finder"
move file the_file to folder the_folder
end tell
The former looks cleaner to me.

HermXIV
11-18-2009, 02:23 AM
What the deuce? I tried that like 5 times before and it never worked. Must have been a typo. =p Thanks man!

NaOH
11-18-2009, 03:37 AM
In case anyone is interested, I took ganbustein's first script and slightly tweaked it so multiple files can be moved at once.

set the_file to (choose file with multiple selections allowed)
set the_folder to (choose folder)
tell application "Finder"
move the_file to the_folder
end tell