{"id":727,"date":"2018-07-05T11:13:20","date_gmt":"2018-07-05T18:13:20","guid":{"rendered":"http:\/\/10.0.1.201\/?p=727"},"modified":"2018-07-05T11:13:20","modified_gmt":"2018-07-05T18:13:20","slug":"auto-eject-drive-folder-action","status":"publish","type":"post","link":"https:\/\/strawhousepig.net\/wordpress\/2018\/07\/05\/auto-eject-drive-folder-action\/","title":{"rendered":"Auto-eject drive Folder Action"},"content":{"rendered":"<p>This script is meant to auto-eject a drive after the amount of time set in the script. It will prompt you first, so you may cancel at that time.<\/p>\n<p>Why would this be useful? I have a <a href=\"https:\/\/amzn.to\/2KEaHZu\">Garmin Edge 130<\/a> bicycle computer. I had been using my phone, but every app\/service has binding arbitration garbage in their 50 page click contract (aka baloney), even so far as with Strava flat out stating they may delete your account if you opt-out of it. Via real mail, of course. Outrageous. So I went with Garmin, who actually have a much smaller click contract. Like a breath of fresh air.<\/p>\n<p>At any rate, my wife also has a <a href=\"https:\/\/amzn.to\/2NAOFoj\">Garmin Forerunner 35 watch<\/a> and, like my Edge 130, includes a drive which mounts on your desktop when plugged into a computer. I believe this drive is used for manually installing watch faces or &#8220;widgets&#8221; and data screens. Although Garmin makes software to load those sort of things.<\/p>\n<p>We typically plug these devices into a computer to charge them and when they are unplugged the Finder complains about the drive having not been ejected properly and file damage or something. Who even reads those things? That&#8217;s where this script comes in and why the trigger is &#8220;GARMIN&#8221;.<\/p>\n<p>This script is meant to be attached as a Folder Action on the <a href=\"file:\/\/\/Volumes\/\">Volumes<\/a> folder.<br \/>\n<code>-- http:\/\/strawhousepig.net\/<\/p>\n<p>-- Name of disks to watch out for.<br \/>\nproperty triggers : {\"GARMIN\"}<\/p>\n<p>-- Number of seconds until the script executes its mission unless user cancels.<br \/>\nproperty TKO : 30<\/p>\n<p>on adding folder items to this_folder after receiving added_items<br \/>\n\tdo_it()<br \/>\nend adding folder items to<\/p>\n<p>on run<br \/>\n\tdo_it()<br \/>\nend run<\/p>\n<p>on do_it()<br \/>\n\ttell application \"Finder\"<br \/>\n\t\ttry<br \/>\n\t\t\tset these_hds to every disk whose name is in triggers<br \/>\n\t\t\tif these_hds is not {} then<br \/>\n\t\t\t\tset now to current date<br \/>\n\t\t\t\tdisplay dialog \"The following volumes will be ejected in \" & (TKO as text) & \" seconds.\" & return & return & these_hds as text with icon 2 giving up after TKO<br \/>\n\t\t\t\tset the_res to the result<br \/>\n\t\t\t\tif gave up of the_res is true then<br \/>\n\t\t\t\t\tmy inspected_detected_and_ejected(these_hds)<br \/>\n\t\t\t\telse<br \/>\n\t\t\t\t\tset now_now to current date<br \/>\n\t\t\t\t\tdelay TKO - (now_now - now)<br \/>\n\t\t\t\t\tmy inspected_detected_and_ejected(these_hds)<br \/>\n\t\t\t\tend if<br \/>\n\t\t\tend if<br \/>\n\t\ton error theErr number theNum<br \/>\n\t\t\tif theNum is not -128 then display dialog theErr giving up  after TKO -- Error -128 is the cancelled by user error.<br \/>\n\t\tend try<br \/>\n\tend tell<br \/>\nend do_it<\/p>\n<p>on inspected_detected_and_ejected(these_hds)<br \/>\n\trepeat with this_hd in these_hds<br \/>\n\t\ttry<br \/>\n\t\t\ttell application \"Finder\" to eject this_hd<br \/>\n\t\tend try<br \/>\n\tend repeat<br \/>\nend inspected_detected_and_ejected<br \/>\n<\/code><\/p>\n<p>Notable is that this script delays the full set time whether the user clicks &#8220;OK&#8221; or not.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This script is meant to auto-eject a drive after the amount of time set in the script. It will prompt you first, so you may cancel at that time. Why would this be useful? I have a Garmin Edge 130 bicycle computer. I had been using my phone, but every app\/service has binding arbitration garbage [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10,14,23],"class_list":["post-727","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-applescript-2","tag-cycling","tag-macintosh"],"_links":{"self":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/comments?post=727"}],"version-history":[{"count":0,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/posts\/727\/revisions"}],"wp:attachment":[{"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/media?parent=727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/categories?post=727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strawhousepig.net\/wordpress\/wp-json\/wp\/v2\/tags?post=727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}