I'm trying to make a script for my magic folder that will move files to a seeding directory without KTorrent losing track of where the data is, similar to the "Move Data" context menu action in the application. I've poked around the dbus API and this is what I have so far:

for x in `qdbus org.ktorrent.ktorrent /core org.ktorrent.core.torrents`; do
    name=`qdbus org.ktorrent.ktorrent /torrent/$x org.ktorrent.torrent.name`
    if [ "$name" = "$1" ]; then
        # Tell KTorrent to move the data to the seeding directory

The problem is that I can't find anything in The API to do that, or even to set the new location after moving it manually.

I played with the idea of doing it by directly manipulating to GUI to activate the context menu action (if I could get that far I'd be satisfied) and found this:

qdbus org.ktorrent.ktorrent /ktorrent/MainWindow_1 org.kde.KMainWindow.activateAction view_move_data

Which does what I want but always for the currently selected torrent, and I can't even figure out the first step to selecting the torrent I actually want to move.

Any ideas?

  • Could you please clarify what it is your script is doing that is different to the Move completed downloads to setting? – Poundex Jul 1 '12 at 21:46
  • It's actually supposed to take a file that's already completed downloading, and then after it's been dealt with, move it elsewhere on demand so it can continue seeding without going through the KTorrent UI. – mcs Jul 5 '12 at 4:09

I found a better solution to my problem. Rather than having my completed downloads moved to a specific directory and then moved back when I'm done with them, I made a KTorrent Script that catches the finished signal and creates a symbolic link to the files in the directory I want to see them in. When I'm done with them I can just delete the symbolic link and never have to move the actual data, which is much more efficient anyway.

I've made the packaged script and source available here:


but I'll post the contents of the main script here just in case.

#!/usr/bin/env kross
# -*- coding: utf-8 -*-
import KTorrent
import KTScriptingPlugin
import Kross

import os
import socket

class FileLinker:
    def __init__(self):
        self.link_dir = KTScriptingPlugin.readConfigEntry("downloads","completedDir",os.path.expanduser("~/"))+"/"
        if self.link_dir.startswith("file://"):
            self.link_dir = self.link_dir[7:]
        KTorrent.log("linkDir is "+self.link_dir)
        KTorrent.connect("torrentAdded(const QString &)",self.torrentAdded)
        tors = KTorrent.torrents()
        # bind to signals for each torrent
        for t in tors:

    def torrentFinished(self,tor):
        KTorrent.log("Symlinking "+tor.pathOnDisk()+" to "+self.link_dir+tor.name())

    def connectSignals(self,tor):
        KTorrent.log("connectSignals " + tor.name())
        tor.connect("finished(QObject* )",self.torrentFinished)

    def torrentAdded(self,ih):
        tor = KTorrent.torrent(ih)

# load settings
linker = FileLinker()

def unload():
    global linker
    del linker
  • That's great, I'love it with a hardlink too. – Drasill Feb 9 '14 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.