{"id":2990,"date":"2013-11-26T09:27:36","date_gmt":"2013-11-26T17:27:36","guid":{"rendered":"http:\/\/manytricks.com\/blog\/?p=2990"},"modified":"2017-03-19T19:59:17","modified_gmt":"2017-03-20T02:59:17","slug":"how-to-start-and-stop-leech-on-a-schedule","status":"publish","type":"post","link":"https:\/\/manytricks.com\/blog\/?p=2990","title":{"rendered":"How-to: Start and stop Leech on a schedule"},"content":{"rendered":"<p><!--RGSupportContent--><\/p>\n<p class=\"stickynote\"><b>Note:<\/b> This article applies to Leech 2; <a href=\"\/\/manytricks.com\/leech\">Leech 3<\/a> has built-in scheduling support.<\/p>\n<p>One feature that <a href=\"\/leech\">Leech<\/a>, our simple download assistant, doesn&#8217;t offer is scheduling. For many users, this isn&#8217;t an issue, as they can use their internet connection whenever they wish. There is a subset of users, though, who have internet connections that may offer more speed at night, or not have capacity limits at night, or may allow unlimited downloading only at night.<\/p>\n<p>A future version of Leech may offer scheduling, but until that comes to be, you can use AppleScript and a scheduling application to handle the task. It&#8217;s not overly complicated, but does require a bit of work in Leech and AppleScript.<\/p>\n<p class=\"floatrightcontainer\"><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2013\/11\/queue.png\" class=\"nonzoomingscreenshot\"><\/p>\n<p>The first step is to have Leech queue up all download requests, so you can just copy and paste URLs into it during the day, then let it run at night. To put Leech in queued mode, just make sure there&#8217;s <b>not<\/b> a checkmark by the Queue > Start Downloads Automatically menu item, as seen in the image at right.<\/p>\n<p>Once that&#8217;s done, you can add URLs to Leech throughout the day, but they won&#8217;t start downloading. Next, you&#8217;ll need to create two AppleScripts, one to start those queued downloads, and the other to pause them again.<br \/>\n<!--more--><\/p>\n<h3>The scripts<\/h3>\n<p>Open AppleScript Editor, in Applications > Utilities, then copy and paste this code:<\/p>\n<div style=\"padding:5px; border:1px solid #ccc; font:monaco,monospace;\">\n<pre style=\"color:black\">\r\n<b>tell<\/b> <i style=\"color:blue\">application<\/i> \"System Events\"\r\n&nbsp;&nbsp;&nbsp;&nbsp;<b>if<\/b> (<b style=\"color:blue\">exists<\/b> (<i style=\"color:blue\">processes<\/i> <b>where<\/b> <span style=\"color:purple\">name<\/span> <b>is<\/b> \"Leech\")) <b>then<\/b>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>tell<\/b> <i style=\"color:blue\">application<\/i> \"Leech\" <b>to <span style=\"color:blue\">activate<\/span><\/b>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b style=\"color:blue\">key code<\/b> 125 <span style=\"color:blue\">using<\/span> {<i style=\"color:purple\">command down<\/i>}\r\n&nbsp;&nbsp;&nbsp;&nbsp;<b>end if<\/b>\r\n<b>end tell<\/b>\r\n<\/pre>\n<\/div>\n<p>This is the &#8220;start&#8221; script, which will tell Leech to start downloading your queued URLs. Note that if you don&#8217;t have any queued downloads, the script won&#8217;t do anything (as it can&#8217;t start a queue that doesn&#8217;t exist.)<\/p>\n<p>Save this script somewhere (such as your user&#8217;s Documents folder), with a reasonable filename (Start Leech). Do not close this window, though, as we&#8217;ll be revisiting it.<\/p>\n<p>Next, open a new AppleScript Editor window (via Command-N, or File > New). In the new window, paste the following code:<\/p>\n<div style=\"padding:5px; border:1px solid #ccc; font:monaco,monospace;\">\n<pre style=\"color:black\">\r\n<b>tell<\/b> <i style=\"color:blue\">application<\/i> \"System Events\"\r\n&nbsp;&nbsp;&nbsp;&nbsp;<b>if<\/b> (<b style=\"color:blue\">exists<\/b> (<i style=\"color:blue\">processes<\/i> <b>where<\/b> <span style=\"color:purple\">name<\/span> <b>is<\/b> \"Leech\")) <b>then<\/b>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>tell<\/b> <i style=\"color:blue\">application<\/i> \"Leech\" <b>to <span style=\"color:blue\">activate<\/span><\/b>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b style=\"color:blue\">keystroke<\/b> \"P\" <span style=\"color:blue\">using<\/span> {<i style=\"color:purple\">shift down<\/i>,<i style=\"color:purple\">command down<\/i>}\r\n&nbsp;&nbsp;&nbsp;&nbsp;<b>end if<\/b>\r\n<b>end tell<\/b>\r\n<\/pre>\n<\/div>\n<p>This is the &#8220;stop&#8221; script, which will put Leech back into pause mode. Save this script (Stop Leech) into the same location as your other script&mdash;and as before, leave the window open.<\/p>\n<h3>Scheduling the scripts<\/h3>\n<p>Now that you&#8217;ve got two scripts, all that&#8217;s left to do is to have them run on your schedule. I&#8217;ll explain how to do this via OS X&#8217;s Calendar application; the directions will differ if you choose to use <tt>cron<\/tt> or <tt>launchd<\/tt> or some other solution.<\/p>\n<p>In order to use Calendar, the first thing you need to do is convert your scripts to applications, because Calendar can&#8217;t run raw AppleScripts (iCal could, but it no longer exists).<\/p>\n<p>In one open editor window, hold down the Option key, then select File > Save As. In the window that appears, change the File Format pop-up to Application, choose a name for your app (it can be the same as the raw script, if you want, as they have different extensions), and save the program.<\/p>\n<p>Do the same for the other window, so that you&#8217;ve now saved two application versions of your scripts. Here&#8217;s how my setup looks, with the applications (left) and original scripts (right):<\/p>\n<p class=\"centercontainer\"><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2013\/11\/leech_scripts.png\" class=\"nonzoomingscreenshot\"><\/p>\n<p>Once the application versions have been saved, launch Calendar and add a new event; the basics don&#8217;t matter, as you&#8217;ll be editing it. Might as well name it Start Leech, though, to help you visually see each task on your schedule.<\/p>\n<p>When the editing window pops up, set the event start time at or after the time when your internet goes to unlimited mode. You don&#8217;t need a long-duration event, so set it for five minutes or similar. Then click on the date to open the scheduling details for the event. Set the &#8220;repeat&#8221; to whatever matches your schedule&mdash;daily, weekends only, whatever.<\/p>\n<p>Next, click on None next to &#8220;alert&#8221; to set the alert for this event. Pick Custom from the pop-up menu; this will open another window (this is progress, really). In that new window, set the first pop-up to &#8220;Open file,&#8221; then pick &#8220;Other&#8221; in the second pop-up.<\/p>\n<p class=\"floatrightcontainer\"><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2013\/11\/event_-config.png\" class=\"nonzoomingscreenshot\"><\/p>\n<p>This will then show the standard Open File dialog; navigate to the folder where you saved the Start Leech (or whatever you named it) application. Select the application (not the script), then click the Select button to close the Open File dialog.<\/p>\n<p>Finally, change the third pop-up menu (the one to set the time of the alert) to &#8220;At time of event,&#8221; then click OK. The screenshot at right shows how my window looked, correctly configured, just before I clicked the OK button.<\/p>\n<p>You&#8217;ve now created a recurring event to start Leech&#8217;s downloads queue at your preferred time on your preferred schedule. Repeat the process with a new event called Stop Leech. Set this one to be triggered sometime before your unlimited internet usage ends, and point it at the Stop Leech application.<\/p>\n<h3>Wrapping it all up<\/h3>\n<p>With the scripts, application, and scheduled events created, you&#8217;re basically done. Go ahead and launch Leech and start queueing your downloads. When your defined start time arrives, Leech should automatically start your downloads, and then pause again near the end of your free usage period. (You may want to test things first by changing the start\/stop times on your scheduled events to a time when you&#8217;ll be at the computer, just so you can see that they do work.)<\/p>\n<p>We realize this is somewhat of a stopgap measure for true scheduling in Leech. However, in testing, it works well, and we hope those of you with time-based internet connectivity find it useful.<!--\/RGSupportContent--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: This article applies to Leech 2; Leech 3 has built-in scheduling support. One feature that Leech, our simple download assistant, doesn&#8217;t offer is scheduling. For many users, this isn&#8217;t an issue, as they can use their internet connection whenever they wish. There is a subset of users, though, who have internet connections that may [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[26,6,4],"tags":[],"coauthors":[21],"class_list":["post-2990","post","type-post","status-publish","format-standard","hentry","category-how-to","category-leech","category-products"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2990"}],"version-history":[{"count":26,"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2990\/revisions"}],"predecessor-version":[{"id":4574,"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2990\/revisions\/4574"}],"wp:attachment":[{"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2990"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/manytricks.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcoauthors&post=2990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}