{"id":31,"date":"2005-09-11T11:38:48","date_gmt":"2005-09-11T18:38:48","guid":{"rendered":"http:\/\/www.red-sweater.com\/blog\/?p=31"},"modified":"2005-09-11T11:47:21","modified_gmt":"2005-09-11T18:47:21","slug":"self-opening-applescript-droplets","status":"publish","type":"post","link":"https:\/\/redsweater.com\/blog\/31\/self-opening-applescript-droplets","title":{"rendered":"Self-Opening AppleScript Droplets"},"content":{"rendered":"<p>Most of the AppleScripts I use are &#8220;plain scripts.&#8221; That is, they require a host application in order to be run. AppleScript also supports the notion of a script application, which can optionally accept &#8220;dropped&#8221; items directly to the script&#8217;s icon. These script applications are commonly referred to as &#8220;droplets.&#8221;<\/p>\n<p>\nMost of my droplets are &#8220;pure droplets.&#8221; By that I mean, they are completely useless to me unless I have actually dropped something on to them. Because of this, and because of the fact that I&#8217;m in the habit of double-clicking &#8220;plain scripts&#8221; in the Finder to bring them up in Script Editor, I often find myself accidentally double-clicking my droplet scripts in an attempt to edit them. This has the unfriendly result of my script simply complaining that it didn&#8217;t get anything dropped on it. I then have to go find the Script Editor and drag the droplet to it in order to edit it.\n<\/p>\n<p>\nIt occurred to me today that I could use the script itself to achieve the desired result. Instead of responding to a double-click launch with no &#8220;dropped items&#8221; by failing, why not just do what I want it do? I added code to the top of one of my pure droplets, which yields the desired effect:\n<\/p>\n<p><pre>\ntell application &quot;Script Editor&quot;\n    activate\n    open (path to me)\nend tell\nreturn\n\non open (dropArgs)\n\t-- Droplet code goes here\nend open\n\n<\/pre>\n<\/p>\n<p>\nNow when I double click the droplet, it kindly asks the Script Editor to open itself for editing. This extra code has no impact on the &#8220;useful&#8221; droplet code, because a droplet&#8217;s code is reached through an &#8220;on open&#8221; handler, which means the implicit &#8220;on run&#8221; code at the top-level of the script is never run except when the item double-clicked.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the AppleScripts I use are &#8220;plain scripts.&#8221; That is, they require a host application in order to be run. AppleScript also supports the notion of a script application, which can optionally accept &#8220;dropped&#8221; items directly to the script&#8217;s icon. These script applications are commonly referred to as &#8220;droplets.&#8221; Most of my droplets are [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-applescript"],"_links":{"self":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":0,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"wp:attachment":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}