Create and send torrent via OS X terminal

18 Oct 2011

Why?

Sending a big file to a friend is sometimes tricky.
Therefore I wrote a small bashscript that creates a .torrent file of the file I want to send.
After that it opens it in the torrent client of my choice and finally creates a new email and attaches the torrent file to it.
The only thing left for me to do after this is to send the email to the person I want to share my file with!

How?

First of all it has a dependency called pyscope it can be installed with ‘easy_install pyscope’.
Next I put this code in my ~/.bash_profile

function createtorrent() {
	FILENAME=$1
	mktor -p $FILENAME udp://tracker.openbittorrent.com:80/announce
	open $FILENAME.torrent
	echo "tell application \"Mail\"
	 activate
	 set MyEmail to make new outgoing message with properties {visible:true, content:\"Torrent file transfer    \"}
	 tell MyEmail
	   make new attachment with properties {file name:((\"$FILENAME.torrent\" as POSIX file) as alias)}
	 end tell
	end tell
	" | osascript
}

Now it can be executed with

createtorrent fileIwantToSend.avi

blog comments powered by Disqus