I need help fixing AppleScript for an app called "Transmission"

I am trying to write code to get it to quit once downloads are finished

Is this the proper code:

    -- Quit Transmission, if running
tell application "System Events"
    if ((count (every process whose name is "Transmission Download")) = 0) then
        tell application "Transmission"
            -- Quit Transmission
        end tell
    end if
end tell

Transmission does not support AppleScript specifically, so there is no way to use AppleScript to check if downloads are still active or not.

There's a concurrent discussion of this idea going on at https://forum.keyboardmaestro.com/t/applescript-for-transmission-app/15789 but this is probably a better place for it, so I'll summarize my answer from there.

  1. Install transmission-cli using brew: brew info transmission-cli

  2. Enable the "Remote" feature of Transmission app:

Transmission Remote Preferences

You do not have to limit to but unless you need to access from another computer, there's no harm in leaving that on.

  1. Enable the feature to remove torrent from the Transmission list after seeding is done:

Transmission Management preferences

  1. Now you can run this script periodically:
#!/usr/bin/env zsh -f


    # the `pgrep` line says 'If Transmission is not running, exit immediately
    # just in case the script happens to be run when the app isn't even running
pgrep -qx Transmission || exit 0

`STATUS=$(transmission-remote --list | egrep -v '^(ID|Sum:) ')`

if [[ "$STATUS" == "" ]]
    osascript -e 'tell application "Transmission" to quit'
    echo "Transmission is still active:\n$STATUS"

exit 0

If Transmission is running, but there are no items in the list, it will be quit.

There may be other ways of doing this, but I cannot think of any myself (other than just using Transmission's preference to run a script when a download is complete, and quitting the app then, but that will fail if there are multiple concurrent downloads active).

|improve this answer|||||
  • I wouldn't run the script periodically, particularly when there's little need to do so in this case. The script can be called each time a download completes and conduct its checks to determine whether it ought to quit at that point or remain open. – CJK Oct 20 '19 at 4:41
  • When a download finishes is only a good time to quit the app if you don't care about seeding. – TJ Luoma Oct 21 '19 at 1:14
  • Quoting the OP: "I am trying to write code to get it to quit once downloads are finished." – CJK Oct 21 '19 at 14:09
  • Fair enough.I was reading it as "finished" meaning both downloading and seeding, but you're right that's not what the OP asked. – TJ Luoma Oct 21 '19 at 19:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .