Folder Action Move Specific File Type to Dropbox

Dear All, please help me out here, my little folder action script doesn´t work although I have tried almost everything here in the list.

I want to make a simple Folder Action to just monitor my Downloads folder and move .torrent files to my Dropbox folder. It should be simple, but neither using name extension or info for seems to work.

This is how I wrote the script so far:

on adding folder items to thisFolder after receiving added_items

tell application "Finder" to repeat with i from 1 to number of items in added_items
	
	set this_item to item i of added_items
	set the item_info to the info for this_item as text
	tell application "Finder"
		if item_info contains "torrent" then
			move this_item to folder "Macintosh HD:Users:Me:Dropbox:Torrents:" with replacing
		end if
	end tell
end repeat

end adding folder items to

I know that this has been up before, and I have tried those solutions too but nothing. I have a new MacBook Pro running OSX 10.6.2 and I believe I have properly configured the folder action, has the script located in the Library/Scripts/Folder Action Scripts etc.

Please give me a hand as to why it does not work?

Model: Macbook Pro
AppleScript: 2.1.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)

I think this should do it:

on adding folder items to thisFolder after receiving added_items
	
	repeat with i in added_items
		-- Path to torrents folder
		set DropboxTorrents to (POSIX file "~/Dropbox/Torrents/") as string
		
		-- if filename contains the torrent extension
		tell application "Finder" to if (name of i) contains ".torrent" then move i to alias DropboxTorrents
	end repeat

end adding folder items to

The tilde does not work at all in conjunction with AppleScript’s POSIX file command,
but there are great solutions to use relative paths


set DropboxTorrents to (path to home folder as text) & "Dropbox:Torrents:"

Ow, sorry, I didn’t know the ~ didn’t work in applescript.

sorry,
ief2

PS: Ow yeah, you also could use

tell application "Finder" to get (folder "Torrents" of folder "Dropbox" of (path to home folder)) as alias

(I don’t really trust the alias to string conversion. I always think applescript is going to forget a “:” at the end)

path to . as text is no coercion. It’s a parameter and it adds always a colon at the end

btw: you also don’t need the alias coercion in your example above

Ow, well yeah, didn’t know that :slight_smile:
Looks like there are always things you can learn.

Thank you all for responding!
The final solution that solved my issue was the one proposed by StefanK. Thanks!
:slight_smile:


on adding folder items to thisFolder after receiving added_items
	
	repeat with i in added_items
		-- Path to torrents folder
		set DropboxTorrents to (path to home folder as text) & "Dropbox:Torrents:"
		
		-- if filename contains the torrent extension
		tell application "Finder" to if (name of i) contains ".torrent" then move i to alias DropboxTorrents
	end repeat
	
end adding folder items to

Model: Macbook Pro
AppleScript: 2.1.1
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)