AppleScript to quit Transmission App
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
quit
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.
Install
transmission-cli
usingbrew
:brew info transmission-cli
Enable the "Remote" feature of Transmission app:
You do not have to limit to 127.0.0.1
but unless you need to access from another computer, there's no harm in leaving that on.
- Enable the feature to remove torrent from the Transmission list after seeding is done:
- Now you can run this script periodically:
#!/usr/bin/env zsh -f
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
# 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" == "" ]]
then
osascript -e 'tell application "Transmission" to quit'
else
echo "Transmission is still active:\n$STATUS"
fi
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).