Using Automator to make your life with Transmission easier

I have two computers: a Macbook with Snow Leopard, that sometimes I carry with me, and a computer at home with an Atom processor and running Linux that is my media server and downloader. If I need to download something that will take too much time, I put this second computer to download: it has a good connection and it’s always online.

It has Transmission running with its great web interface activated. If I need to download some torrent file, I open its web interface and upload the .torrent file. Good, but… it could be easier.

If you download torrent files very often, the easiest way is to use the watch-dir feature from Transmission: every torrent that you put at some directory is automatically downloaded by Transmission. So, all I needed to do was copying the torrent files from my Macbook to my home server, using SFTP.

To configure your Transmission watch-dir, you must stop the Transmission service (I’m running the transmission-daemon version) and edit the settings.json file, inserting the following settings:

"watch-dir": "/home/mediaserver/transmission/watch",
"watch-dir-enabled": true

Remember: you must stop Transmission service, edit the file and start it again!

It works, but… It can be even easier, I thought. And I remembered of Automator, a good piece of software that comes with Snow Leopard, and that I knew but never used before.

The idea was: every time a new .torrent file is written at my laptop’s download directory, it should be copied to my home server.

So I opened Automator and created a new Folder Action:

At the top of the new workflow, I selected my Downloads folder:

 The next step in our flow is to create a script to copy our files via SSH to the computer that’s running Transmission. Use Utilities -> Run Shell Script to make it:

Now add the following content as the script’s source code. To make it work automatically, I allow my SSH server to receive connections using keys, not passwords. Don’t forget to change the scp’s destination to your computer’s host and directory:

for f in "$@"
	ext=`basename "$f" | awk -F "." '{ print $NF }'`
	if [ "$ext" == "torrent" ]; then
		scp "$f"

That’s it! Save your workflow and test it. Now, every time you click at a torrent file and download it, Transmission will download it automatically.

Listing the packages on Debian/Ubuntu in one line

You can use dpkg to list all the packages that are selected on your Debian or Ubuntu system:

# dpkg --get-selections

But today I needed a way to list only the installed packages in just one line, so I could copy their names and use apt-get to install the same packages on another system. So I used the following command:

# dpkg --get-selections | grep "[ \t]*install$" | sed 's/[ \t]*install$//g' | awk 'BEGIN { packages = "" } { packages = packages " " $1 } END { print packages }'
acpi-support-base acpid adduser apt apt-utils [...] long list of packages [...] xsltproc xz-utils yelp zenity zlib1g zlib1g-dev

You can use the output above to easily install the same packages on another system using apt-get install <packages>.

Baixando pacotes pré-compilados no FreeBSD

Após instalar o FreeBSD 8.0 no meu modesto computador para tarefas rotineiras, veio a necessidade de instalar alguns pacotes. O FreeBSD tem duas modalidades de instalação de pacotes:

  • O sistema de ports, que automatiza a tarefa de baixar código-fonte e compilá-lo, além de adaptar alguns pacotes ao seu gosto: o sistema ajuda você a habilitar ou desabilitar opções de vários pacotes, como suporte a Unicode, X11, bibliotecas adicionais etc.
  • Pacotes binários pré-compilados, familiares pra quem vem do Linux (como eu).

O FreeBSD possui uma ferramenta simpática chamada pkg_add que lembra o apt-get, pacman ou yum do Linux, baixando pacotes nos repositórios do FreeBSD. Porém, ao pedir pro pkg_add instalar alguns pacotes, como o Transmission, ele instalou versões mais antigas. Fuçando no FTP do FreeBSD, achei pacotes mais recentes dos pacotes. A próxima briga foi pra fazer o pkg_add usar apenas esses pacotes mais novos (dum diretório amigavelmente chamado Latest).

O truque é simples: quando você executa pkg_add -r nomedopacote, o pkg_add busca por $PACKAGESITE/nomedopacote.tbz. Se você fuçar pelos diretórios dos mirrors do FreeBSD vai perceber que os pacotes normalmente se chamam nomedopacote-versão.tbz, exceto os do diretório Latest, que instalam automaticamente a última versão disponível. Nos comandos abaixo, reparem que usei o sistema para arquitetura 64 bits (amd64), se sua instalação for para x86 32 bits, troque amd64 por i386.

Assim, pra instalar o vim, usei o seguinte comando no bash:

[root@tinhoso /home/esdras]# export PACKAGESITE=""
[root@tinhoso /home/esdras]# pkg_add -r vim

Você pode, ainda, acrescentar o comando do export no seu arquivo ~/.profile, o que fará o comando ser executado automaticamente a cada login:

[root@tinhoso ~]# echo export PACKAGESITE=\"\" &gt;&gt; ~/.profile

Caso você use csh (shell padrão no FreeBSD!), o comando muda:

tinhoso# setenv PACKAGESITE
tinhoso# pkg_add -r nano
Para tornar a variável permanente, acrescente esse comando no arquivo ~/.cshrc:

tinhoso# echo setenv PACKAGESITE >> ~/.cshrc