Page 1 of 2

Quit Transmission automatically

PostPosted: Thu Jul 18, 2013 11:13 am
by Jitto
Hey there,

Does anyone how i can assign an automated way of quitting tranmission automatically once the download has been completed?

I tried a few commands for calling for script - to shut down but it didnt work. Wondering if there is any solution to this?

thanks in advance

Re: Quit Transmission automatically

PostPosted: Thu Jul 18, 2013 12:09 pm
by sjk
What condition do you want Hazel to use to detect that "the download has been completed"? Once you've got that, this one-liner shell script should quit Transmission:

Code: Select all
/usr/bin/killall -c Transmission

Re: Quit Transmission automatically

PostPosted: Thu Jul 18, 2013 12:50 pm
by Jitto
Thank you very much for your reply. :).

ANd yes i want transmission to quit once it has downlaoded the file. How do i exactly configure this so that hazel recognizes this? or do is there way to include it in your shell script?

PS. i have automated hazel to move the files from the download folder to a designated folder where i want the files to be. and hazel usually runs this command once the download has been completed.

thanks again

Re: Quit Transmission automatically

PostPosted: Thu Jul 18, 2013 3:40 pm
by sjk
Jitto wrote:ANd yes i want transmission to quit once it has downlaoded the file.

Presumably you want it to quit after it's finished downloading all files?

… and hazel usually runs this command once the download has been completed.

Not sure what you mean by "usually runs", but maybe you can also have Hazel run the "/usr/bin/killall -c Transmission" script after the download's done?

If you post the Hazel rule(s) you're already using it'll be clear(er) what's happening and easier to make specific suggestions. Thanks.

Re: Quit Transmission automatically

PostPosted: Thu Jul 18, 2013 5:34 pm
by Jitto
Thank you so much for your kind reply. I am terribly sorry but its just that Im a noob when it comes to hazel seeing as i just bought it and am still figuring my way out.

Actually, I havent made a hazel rule as such to quit transmission. All thet ive made so far is to transfer the completed download file to another designated folder.

In essence, what i want is transmission to quit after it completes the download. Exactly what can I do to make this happen? Do i really need hazel for this or do i need to just attach a shell script to the "run shell script" option in transmission?

Re: Quit Transmission automatically

PostPosted: Thu Jul 18, 2013 7:24 pm
by sjk
Jitto wrote:Actually, I havent made a hazel rule as such to quit transmission. All thet ive made so far is to transfer the completed download file to another designated folder.

You might be able to add the script that quits Transmission to the same Hazel rule that moves the completed downloaded file. It would be useful to see the current rule.

Re: Quit Transmission automatically

PostPosted: Fri Jul 19, 2013 5:34 pm
by Jitto
Hey there,

thanks again for your reply. Here is a sample rule i use

for instance i download comicbooks and have hazel transfer them to a designated Comics folder. Here is a screen shot of it

The downloads folder refer to where transmission saves files

Image


I have several other similar rules like this but its all in the exact format

Re: Quit Transmission automatically

PostPosted: Sat Jul 20, 2013 10:47 pm
by sjk
Thanks for the helpful image and explanation, Jitto. Much clearer now. :)

Transmission doesn't directly support auto-quit after downloading, as you know, and it's unlikely to be implemented; see this request that was closed with wontfix resolution:

#2925 (Feature Request - Auto Close at Completion) – Transmission

Auto-quitting encourages "hit and run" downloading, leeching without seeding, which can be considered uncool but it also has valid uses. Before posting some new auto-quit ideas I wanted to ask if you're sure you want to do that. I'm curious the reason(s) but you don't have to tell me. :)

Re: Quit Transmission automatically

PostPosted: Sun Jul 21, 2013 10:45 am
by martinewski
I'm against this, because as SJK said, it is bad behavior.

I'm sure you'll quit it because you really need to at that particular moment, but you'll seed later, correct? :wink:

Now, what you could do is create a rule to watch the temporary download folder (the one where partially downloaded files are kept and where they are moved from after the download completes) and when the Sub-file/Folder count is equal to zero, quit Transmission using the script previously posted by SJK too.

That's how I would do it if I was a leecher :roll:

Just don't forget to pause the folder monitoring if you're not downloading anything, or it will quit Transmission every time you open it.


Image
Image

EDIT:

After reviewing and testing the rule, you should actually monitor the parent folder and create a rule to evaluate the downloads folder, as the evaluation is "sub-file/folder count".

In my case:
Code: Select all
If Kind is Folder
If Name is transmission downloads
If sub-file/folder count is 0

Run Shell Script... {the script SJK provided}

Re: Quit Transmission automatically

PostPosted: Sun Jul 21, 2013 12:02 pm
by Jitto
Thanks very much for your replies guys;

The reason why I ask this is because I usually download whatever i need ASAP via transmission and ONLY seed them at night when i go to bed so that by morning it should have finished seeding all those that I've downloaded.

During the day Im mostly busy online doing business related stuff so I can't over-load my bandwidth, Hence why i wanted to ask if there was a way to actually automatically quit transmission w/o manually doing it so that it doesnt interfere with my work. Hope that helps

Re: Quit Transmission automatically

PostPosted: Sun Jul 21, 2013 4:59 pm
by sjk
martinewski wrote:That's how I would do it if I was a leecher :roll:

Interesting. Using a separate folder for incomplete files hadn't occurred to me, but could fit well with an idea I had in mind that doesn't rely on Hazel …

Under the Management tab of Transmission > Preferences > Transfers the "Call script: when download completes: <script>" setting can be enabled with a selected shell script to run after each download completes. Since you probably don't want Transmission to quit while other downloads are still in progress the script needs to test for that condition. Here's a simple example that checks for incomplete downloads (with a .part extension) and kills Transmission if there aren't any:

Code: Select all
#!/bin/sh

PATH=/usr/bin
TR_DOWNLOADS=/Path/To/Transmission/Downloads

[[ $(find "${TR_DOWNLOADS}" -name '*.part') == '' ]] && killall -c Transmission
exit

It assumes all incomplete downloads are under a single /Path/To/Transmission/Downloads folder. But if you configure to use a separate folder for that, like in martinewski's example, then the script only has to check there.

That's the basic gist.

One issue I've discovered is that using killall … to quit Transmission can leave files in a inconsistent state that causes redundant downloading next time it's run, which seems to be avoided by substituting this bit of shell+AppleScript:

Code: Select all
osascript -e 'tell application "Transmission" to quit'

Two caveats:

• By default, Transmission prompts to quit if transfers are active (e.g. seeding what just finished downloading). Disabling "Prompt user for:" settings under Preferences > General can work around that.
• Being run as an uncompiled script causes Transmission to launch if it isn't already running. Irrelevant in this context but doesn't hurt to be aware of.

Transfer list cleanup is a separate issue. Enabling "Remove from the transfer list when seeding completes" under Preferences > Transfers / Management can help automate that.

Hopefully you've got enough information now, Jitto, to make Transmission auto-quit the way you'd like. And it's no longer a Hazel issue with my method. Anything else that's Transmission-specific might be more appropriate for its forum.

Re: Quit Transmission automatically

PostPosted: Sun Jul 21, 2013 5:35 pm
by Jitto
Thank you very much SJK for your comprehensive method. Ill be sure to try it out and failing which ill try checking with the transmission forum.

Much appreciated with your help on this

Re: Quit Transmission automatically

PostPosted: Sun Jul 21, 2013 5:51 pm
by Jitto
Also sorry to question this, but it is possible to create the script you mentioned using applescript editor right?

Re: Quit Transmission automatically

PostPosted: Mon Jul 22, 2013 12:36 am
by sjk
Jitto wrote:Also sorry to question this, but it is possible to create the script you mentioned using applescript editor right?

Nope; these are the steps:

  • Copy the script below into a plain text editor and change /Path/To/Transmission/Downloads to the correct folder(s) on your system
  • Save edited script to a file, e.g. /Users/username/bin/quit-transmission
  • Set script's execute bit, e.g. run chmod +x /Users/username/bin/quit-transmission in Terminal
  • Select script with Transmission's "Call script: when download completes:" setting (mentioned in my previous reply) and enable that
  • Test :)
Code: Select all
#!/bin/sh

PATH=/usr/bin
TR_DOWNLOADS=/Path/To/Transmission/Downloads

[[ $(find "${TR_DOWNLOADS}" -name '*.part') == '' ]] && osascript -e 'tell application "Transmission" to quit'
exit

Re: Quit Transmission automatically

PostPosted: Mon Jul 22, 2013 8:44 am
by Jitto
Gotcha thanks....Worked like a charm :) Much appreciated.