Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use AppleScript and Mail to auto-start torrent downloads Apps
Can't download torrents from the office? Find yourself emailing them home so you can start them when you get there? Ever Ever wished your home Mac would just start downloading them straight away? If you answered yes to those questions, then this tip is for you.

You're going to set up an AppleScript Mail filter that picks out attached torrents, and then uses Azureus to download them. First, download the Applescript (8KB) (macosxhints mirror).

Save it somewhere sensible; I chose /Library/Scripts. Next, you'll need to add the rule to Mail. In Mail's Preferences, click Rules then Add Rule. Set up the From and Subject lines as they apply. For instance, my rule checks that From Contains my surname, and that Subject Contains download torrent. As for Perform the Following Actions, select Run AppleScript, and choose the AppleScript you just downloaded. Select OK. You're nearly there...

In Azureus, you'll need to make a slight change: In Options -> Files, you'll find Save to Default Data Directory. Ensure that this checkbox is checked. And there you have it. Enjoy! You can also find these instructions with screenshots here.

[robg adds: In the script mirror on hints, I've commented on one line you'll want to change -- the path to the default save directory. This hint is interesting not just for the stated purpose, but as an example of using AppleScript and Mail's rules to automatically handle inbound attachments.]
    •    
  • Currently 2.50 / 5
  You rated: 3 / 5 (8 votes cast)
 
[32,137 views]  

Use AppleScript and Mail to auto-start torrent downloads | 18 comments | Create New Account
Click here to return to the 'Use AppleScript and Mail to auto-start torrent downloads' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use AppleScript and Mail to auto-start torrent downloads
Authored by: ob1cannoli on Jun 14, '06 07:49:26AM
How about installing the Azurues Swing Web Interface plugin? After some simple port fowarding on your router and a signup with http://dyndns.org you'll have an easy way to check on the status of your downloads and upload torrent files to start them! Not to mention the fact that the site is password protected too. Just launch the Azureus Plugin Wizard from the menu...

[ Reply to This | # ]
Use AppleScript and Mail to auto-start torrent downloads
Authored by: mattcomi on Jun 14, '06 08:37:47AM

Yeah, I agree, the web front end to Azureus is pretty cool, but notice my comment: "Can't download torrents from the office?"

At my office we can only access port 80 and my router doesn't let me forward port 80, so I needed an alternative.

---
Big Bucket Amusement
http://members.iinet.net.au/~mattcomi/mt/bigbucket



[ Reply to This | # ]
Use AppleScript and Mail to auto-start torrent downloads
Authored by: nickdynamite on Jun 14, '06 08:39:44AM

is there a way in Applescript to quit an application (such as Bittorrent)?

I ask because I want to use iCal to set up an event to, say, stop bittorrent before I get up - say at 6am. I've set up iCal events that launch applications before just wondering if there's a way to have a corresponding event to quit an app.

Thanks in advance..



[ Reply to This | # ]
yep
Authored by: fracai on Jun 14, '06 09:28:22AM

tell application <app name>
quit
end tell

---
i am jack's amusing sig file



[ Reply to This | # ]
yep
Authored by: nickdynamite on Jun 14, '06 10:08:47AM

tell application BitTorrent
quit
end tell


tried that didn't work.

"Applescript Error

The variable BitTorrent is not defined."



[ Reply to This | # ]
yep
Authored by: fredrikw on Jun 14, '06 10:34:22AM

You need to enclose the application name in quotes...

tell application "BitTorrent"...

/Fredrik



[ Reply to This | # ]
yep
Authored by: nickdynamite on Jun 14, '06 12:07:30PM

got it thanks, n00b applescripter here ;)



[ Reply to This | # ]
Use AppleScript and Mail to auto-start torrent downloads
Authored by: gxw on Jun 14, '06 05:11:20PM

it should be someting like:
tell application app_name to quit
end tell
in apple script.
app_name == the name of the app to quit like itunes.



[ Reply to This | # ]
Use AppleScript and Mail to auto-start torrent downloads
Authored by: chyna4xena on Jun 15, '06 05:22:39PM
I don't think you should have the "end tell" line, when the "tell" command is all on one line.

Either
tell application "app_name"
     quit
end tell
Or
tell application "app_name" to quit


[ Reply to This | # ]
Another (better?) way
Authored by: stevebr on Jun 14, '06 08:18:57PM

Nick, you already have the scripted solution, but I'll make the following suggestion:

1) Use Azereus instead of the official BT client.
2) Install & set up the Azereus plugin called "Speed Scheduler." Azereus has a plugin manager (available in the "Plugins" menu) that will assist you in installation and configuration.

Speed Scheduler may be exactly the thing you are looking for. It's much more flexible than an on|off switch like you can get with "Tell application x to quit". I use it adjust allocated bandwidth (upstream and downstream independent of one another) with a schedule that includes different allocations for typical working hours, overnight, and weekends. You can also set either upstream or downstream bandwidth to zero in any schedule, which should solve your initial problem.



[ Reply to This | # ]
possible security risks
Authored by: hayne on Jun 14, '06 08:49:28AM

You should realize that anytime you set up something like this you are opening your system to possible security problems.

It is quite easy to forge the sender's name (or any other part) of an email message. Thus anyone could send you an email that would trigger your script.
Would you feel comfortable double-clicking on a ".torrent" file that some stranger emailed to you? You've set this up so a malicious stranger can send you ".torrent" files and effectively automatically double-click on them!

Note also that it is perhaps possible (in theory - I don't know details of Azureus) for ".torrent" files to contain some other type of file that Azureus would read and recognize as being that other type in spite of the ".torrent" suffix. That might open further security holes.

I would strongly recommend that you incorporate at least some simple security measures in your script. E.g. check on the address the email was sent from as well as the sender's name. Make it so that the script only triggers if the subject line contains some special code word that only you would know. Maybe this code word could depend on the current date or the name of the torrent (e.g. every second letter of the torrent name, followed by the day of the month).



[ Reply to This | # ]
possible security risks
Authored by: robg on Jun 14, '06 09:19:28AM

While there's clearly some risk here, I think it's minimal -- an attacker would have to know (a) what you use for the subject of your email to yourse, and (b) spoof the from address to use your surname.

But as you note, it's simple to add extra protection; even doing something as simple as 'Subject equals Törrént D0wn7oad" would probably suffice.

I don't do much with torrents (occasional Fedora releases), but I like the options that this script enables for remote mail handling.

-rob.



[ Reply to This | # ]
Use AppleScript and Mail to auto-start torrent downloads
Authored by: solipsism on Jun 14, '06 09:35:43AM

This rocks. Thanks.



[ Reply to This | # ]
Use AppleScript and Mail to auto-start torrent downloads
Authored by: Whosawhatsis on Jun 14, '06 12:09:16PM
I use Hamachi VPN to keep a Bonjour-compatible network connection to my home server from my laptop. With this setup, I can just drop the torrent file onto an alias of the torrents folder and it will automatically mount the AFP share and transfer the file, then a Proxi rule on the server autostarts the torrent and sends a growl notification back to let me know it worked.

---
I was offered a penny for my thoughts, so I gave my two cents... I got ripped off.

[ Reply to This | # ]

Just use Azureus Widget
Authored by: thayneq on Jun 14, '06 04:19:53PM
Hey just use the Azureus Widget. You just drag a torrent onto the widget, and it automatically sends it and starts it on your server at home! It's simple, works over the internet, and gives you full control over your azureus running at home. You can set it up through a VPN if you want more security or through hamachix. Simple, and easy, and works every time! Azureus Widget

[ Reply to This | # ]
Terribly Insecure
Authored by: onan on Jun 16, '06 12:38:15PM

Mail is a fundamentally insecure medium, and the notion of your computer just happily accepting email and automatically running things based upon it is horrifying.

Remote access to and control of your machine is a perfectly reasonable thing to desire, but mail (or IM, or remote applescript) is not the way to do it. There's a reason that Benjamin Franklin discovered ssh!




[ Reply to This | # ]
Use AppleScript and Mail to auto-start torrent downloads
Authored by: dev_sleidy on Jun 16, '06 03:07:52PM

As per robg's statement - '... you'll want to change -- the path to the default save directory.', replace ...

set filename to "Macintosh HD:Users:mattcomi:Desktop:td_" & nameOfAttachment

... with ...

set filename to ((path to desktop from user domain) as string) & "td_" & nameOfAttachment

... for use on anyones Macintosh.



[ Reply to This | # ]
Use AppleScript and Mail to auto-start torrent downloads
Authored by: critcol on Jul 05, '06 07:12:00PM

Also, as shown to us by the Leap.A virus, OSX malware needs to be activated by the user. Assuming that Azureus will only open .torrent files and there's no embedded malware (I haven't heard of other types of data being hidden within a torrent file, due to their extremely small size and use of MD5 hashes), the user would still have to activate whatever was downloaded before it could effect or damage their system.

Basically, the idea this could be used for evil purposes is defeated when the user gets home, looks at their download folder and says, "huh?"

We just have to hope the user is smart enough to Get Info before double-clicking and entering the admin authentication...



[ Reply to This | # ]