Pixelbox

Welcome to Pixelbox. Thursday the 20 of November 2008

Skip to content >>

Remote torrent downloading

Ever been at work and wanted to download a torrent you have found bit instead had to wait (and usually forget) until you get home to download it? Well there is hope and it doesn't involve complex NAT forwarding and remote desktop connections to your home computer.

No instead it involves a few lines of apple script and mail. Oh and of course Mac OS X. Using mail you can set up a little rule, as I often did to remove spam to pick up mail based on certain constraints and then perform a few tasks like re-colour it, move it to a folder, but more importantly run some apple script!

So set up a rule to look for something like "download this torrent" in the subject (don't want your friends finding out and sending you gay pr0n torrents, well unless that's your bag. So you may want to set it to something more ambiguous). Now choose "Run Applescript" from "Perform the following actions:" and point mail in the direction of the apple script your about to write... (OK perhaps I should have done that step first.)

Open up Script Editor.app from Applications->AppleScript and paste in this code:


using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			
			set numberOfMessages to count theMessages
			
			repeat with eachMessage in theMessages
				
				set theSubject to subject of eachMessage
				
				try
					set nameOfAttachment to the name of the first mail attachment of eachMessage
					
					if nameOfAttachment ends with ".torrent" then
						
						set filename to "Macintosh HD:Users:YOUR_USERNAME_HERE:Desktop:td_" & nameOfAttachment
						
						save first mail attachment of eachMessage in filename
						
						tell application "Script Editor"
							set torrent to open file filename
							open torrent
						end tell
						
					end if
					
				end try
				
			end repeat
			
		end tell
		
	end perform mail action with messages
	
end using terms from

Obviously you need to change the line "Macintosh HD:Users:YOUR_USERNAME_HERE:Desktop:td_" to reflect the path to your desktop changing Macintosh HD to the name of your hard drive and "YOUR_USERNAME_HERE" to... you guessed it... your user-name (the name next to the little house in the side bar of a finder window)! Lastly change Script Editor to the name of your torrent application, such as Transmission.

So once you have clicked compile and saved it, go back to where we were and point mail at it. Now when you send a message that meets those rules you set up your torrent will start magically downloading... Pr0!

For more info that may help you I found out about this in the first place from mac osx hints.

Meta tags: Mac OS X

There are no comments yet

Add your own comment