Move selection to container of selection

The GUI Finder makes it easy to move files around, especially when moving files deeper into folders. i.e. drilling down is very nice. But I don’t know of any way to quickly move files/folders UP a level into a conatining folder. Something from the command line like “mv myFile …”

So, I thought it would be easy to make a short droplet script to put in the toolbar of the finder windows that would do this. My approach was to use something like

move selection to container of selection

but that doesn’t work. I could not find anything else that would work either.

I have an idea for a much longer script but I was wondering if anyone has ideas about how to do this easily?

Scott

What you want to do can be done, but it needs to be done on a file-by-file basis (the ‘selection’ is a list and you can’t move a list of files to ‘container’ since each file could have a different contains.

Therefore:

on open dropped_files
   repeat with eachItem in dropped_files
      tell application "Finder" to move eachItem to (container of eachItem)
    end repeat
end open

Hi,

Actually, you can use the Finder’s move command on lists. Sometimes when you use Finder properties (selection, container, etc.) you may need to break up the statements and get one at a time. Here’s an example application (not droplet) that you can place and run in a Finder task bar and it will move the selected items up one container.

tell application “Finder”
activate
set the_sel to (selection)
set il to insertion location
move the_sel to (container of il)
end tell

Needs error checking.

gl,

Thanks Camelot and kel,

Camelot’s script didn’t work at first. I realized I was trying to do the same thing. The important line should be:

tell application "Finder" to move eachItem to ([b]container of[/b] (container of eachItem) )

The container of the file is the folder it is in. So it doesn’t move! Otherwise it works great and is exactly what I was trying to do.

kel’s script was faster because it could move all the files at once. I don’t think this will be a problem in the case of the finder because you cannot select several items in different folders at the same time.

I haven’t tested any of the code offered here but what happens if there’s a file in the target destination with the same name as one which will be moved there by the script? Have you added code to deal with this possibility?

– Rob

As the code is written it will not move files that exist in the target destination and give an error saying so. To catch the error use:


tell application "Finder"
	activate
	try
		set the_sel to (selection)
		set il to insertion location
		move the_sel to (container of il)
	on error
		display dialog "Some items exist in the destination"
	end try
end tell

This will move the files that do not exist in the target destination, but not the others.

Scott