Move Files Droplet

First let me apologize for posting such a simple question, but I’ve searched and searched and can’t make it work.

I have a droplet, and I want it to take files, move them, and add them to itunes. I can’t get past the move stage. I’ve tried a thousand variations and I’m really pulling my hair out on this one. Someone please help while I still have some hair left!!!

on open FileList
	repeat with YourFile in FileList
              set YourFile to YourFile as Unicode Text
		tell application "Finder" to move YourFile to (folder "Volumes:Jamie's HD:Music:Added thru Scripts")
	end repeat
end open

I’m new to scripting and haven’t tried scripting iTunes yet, so I can’t help you with code. I can tell you that adding files to your music folder certainly won’t get them added to the iTunes Library. You have to tell itunes to import the song files… that’s the only way I know of to have the iTunes library updated with the new songs.

So my basic idea for a script would be:

  1. tell application “iTunes” to import FileList – if your itunes prefs are set then itunes will make copies of the files and put them in the proper place within your music folder
  2. tell application “Finder” to move FileList to trash

It isn’t the iTunes part I’m worried about, that I can manage. But I can’t actually move the files!!!

Jamie:

I am sorry I don’t have time right now to completely test this snippet, but it worked last summer for me:

repeat with tt from 1 to (count tlist)
	tell application "iTunes"
		set this_one to item tt of tlist as alias --NEEDS the [as alias] to function
		add this_one to first library playlist --adds the track
	end tell
end repeat

Where tlist is a list of file paths. I believe you can also use a playlist name like this:

add this_one to playlist "Driving"

Let us know how you fare.

Nope, like I said, the iTunes part is easy. It keeps throwing me the error “can’t get item 1 of alias …” when I try to move a file.

I just tested this and it works. You highlight some files in a finder window and run it.


tell application "Finder"
	set these_items to the selection -- this statement is what passes the highlighted files to the script
	repeat with i from 1 to the count of these_items
		set sourceFile to item i of these_items as alias
		tell application "iTunes"
			add sourceFile to first library playlist
		end tell
	end repeat
end tell

This will copy the highlighted files to a new location (destinationFolder) and move the original files to the trash…


set destinationFolder to "MacOSX:Users:hmcshane:Desktop:untitled folder:"
tell application "Finder"
	set these_items to the selection -- this statement is what passes the highlighted files to the script
	repeat with i from 1 to the count of these_items
		set sourceFile to item i of these_items as alias
		duplicate sourceFile to destinationFolder -- this makes a copy of the file in the destination folder
		move sourceFile to trash -- this moves the original file to the trash
	end repeat
end tell

One thing I noticed about your code was you’re missing a “:” at the end of your folder path i.e.

change
“Volumes:Jamie’s HD:Music:Added thru Scripts”

to
“Volumes:Jamie’s HD:Music:Added thru Scripts:”

Nope, ignore the iTunes bit. I want to move the file to another folder. This is the error I get
Finder got an error: Can’t get alias “JL’s Mac:Users:JTL:Desktop:01”

Try this… changing your destinationFolder


on run
	-- this is displayed if you double click the droplet
	display dialog "Files dragged onto me will be moved to \"Desktop:untitled folder:\"" with icon note
end run

on open these_items
	set destinationFolder to "MacOSX:Users:hmcshane:Desktop:untitled folder:"
	tell application "Finder"
		repeat with i from 1 to the count of these_items
			set sourceFile to item i of these_items as alias
			move sourceFile to destinationFolder
		end repeat
	end tell
end open

Thanks for all you help, but it still won’t work.
I copied your script into script editor and made a droplet, and it still throws the error saying that it can’t find the alias. It lists off the whole source, and it seems to be right too! Why is it doing this!

Jamie:

Which version of OS X are you using?

I had a few problems myself with the script below, until I created the destination folder, entitled untitled folder. After that, it worked fabulously in OS X 10.4.8:


on run
	-- this is displayed if you double click the droplet
	display dialog "Files dragged onto me will be moved to \"Desktop:untitled folder:\"" with icon note
end run

on open these_items
	set destinationFolder to (path to desktop as Unicode text) & "untitled folder:"
	tell application "Finder"
		repeat with i from 1 to the count of these_items
			set sourceFile to item i of these_items as alias
			move sourceFile to destinationFolder
		end repeat
	end tell
end open

So, just create the native new folder onto the desktop (shift--N), and drop files onto the droplet all you want.,

Version 10.4.8

Jamie:

You are too fast. See my edit above.

Tried it, it has nothing to do with the destination folder. It tells me it “can’t get alias …” of the file I drop into it. Thanks again for all your help, this is really driving me nuts and I appreciate the support!

That is atounding!! I got the exact same error until I made the folder, then it worked great. In fact, I just now changed the name of the destination folder, and got the same error. Changing the name back to untitled folder put it back to working perfectly.

I am not versed in all the different error codes and how to track these things down, but my limited experimentation shows that I only get that error if there is a problem with the path to the destination folder. I don’t want to sound like your mother-in-law, but are you POSITIVE that your destination path is clean, correct, and in existence?

Thank you thank you thank you!!! I was sending it to my external drive, and I added “volumes” to the front of the path. I removed it and it worked. Sorry to put you through all this for such a little error. What I still don’t get is why the error was about the file, not the folder. Anyway, thanks for your help!

Yeah, I thought the same thing about the error when it first came to me. I could not see why it stated that it could not get the alias, when you had to select the dumb thing in the first place!!

I’m glad it’s all sorted out now; I can go to bed worry-free.

That’s why I got in the habit of typing “choose folder” (or file) in a new script window and running it, choosing the folder, and copying the address from the result window. It’s just too easy to make a simple mistake like that.

Anyway, I’m glad you’re fixed.