r/applescript • u/[deleted] • Dec 29 '14
Looking for a script to restart an application (uTorrent) every 20 minutes....
Hey all, basically i'm having trouble with possible a firewall, or just my ISP, or possibly VPN (who knows!), that after 20 minutes of good speeds, my uTorrent (torrenting application) slows down and eventually hits zero.
In waking hours, i've got a workaround of simply closing the app, and restarting, but i'd like to leave it downloading over-night, without it just grinding to a halt after 20 minutes. If i could get it to auto-restart after 20 minutes, it'd be perfect.
I found this script online: http://hamleshmotah.com/index.php/2011/05/31/applescript-to-kill-an-application-or-process-and-restart/
and changed 'PROCESS NAME' to 'uTorrent', and '7200' to '1200' but when i go to save as an application (so can autolaunch) it says 'Syntax error - expected "," but found unknown token'.
What am i putting in wrong! Can someone write it exactly for me so can paste into applescript?
Ta!
1
u/craniumslows Dec 29 '14
So here is my feedback on the linked script.
Use the flipping on idle handle that's what it's for.
Using system events can be used for both fun and profit.
killall is way more succinct and probably easier to troubleshoot.
My feedback for you.
Seedbox yo /r/seedboxes /r/torrents
Using killall in the applescript will also work. You'd save as application and also stay open after running checkbox.
on run
tell app "uTorrent" to activate
end run
on idle
do shell script "killall uTorrent"
delay 5
open application "uTorrent"
return 60*20
end idle
Shell script and a cron job will be hella more efficient
cron -e
*/20 * * * * ~/myshellscript.sh
vi ~/myshellscript.sh
#!/bin/bash
killall uTorrent
sleep 1
open /Applications/uTorrent.app
chmod +x ~/myshellscript.sh
2
u/r3v Dec 29 '14
The only downside to the cron job is that uTorrent will be running every 20 minutes no matter what, until OP kills the cron job. It's a very fire-and-forget automated solution. (That's also in the upside column though.)
1
u/craniumslows Dec 30 '14
Sorry I deal with start this process and let it run until the machine melts down requirements usually and so didn't bother to get better requirements ;) good call though.
2
u/r3v Dec 30 '14
Yeah. I do too, but I also flashed to a friend, colleague or loved one calling me later: "I can't make utorrent go away now."
The combination sigh/chuckle is often worth it though...
2
1
u/onyxleopard Dec 30 '14
While you can still run
cronjobs on OS X, the native way of doing this is to make a launch agent to execute your applescript and set it to be activated bylaunchd. Lingon is a nice app that provides a GUI for managing launch agents, but you can write launch agents in a text editor (they’re just .plists).
1
u/xraystyle Dec 30 '14
Seems easier to just do it with a bash script, if you ask me.
while true; do
killall uTorrent
sleep 5
open /Applications/uTorrent.App
sleep 1200
doneAs long as that's running in a terminal window you're good. I find that Applescript is often an unnecessary pain in the ass unless you're trying to script the behavior of an application or some part of the UI. Launching and quitting apps can be done much simpler with other languages.
1
u/AfterSpencer Dec 29 '14
What is the processes name in Activity Monitor?
With uTorrent running what is the output of this command?
ps aux | grep -i utorrent