{"id":124,"date":"2010-02-12T16:56:37","date_gmt":"2010-02-12T23:56:37","guid":{"rendered":"http:\/\/www.dreness.com\/blog\/?p=124"},"modified":"2010-02-16T12:12:37","modified_gmt":"2010-02-16T19:12:37","slug":"applescript-studio-variable-stacking","status":"publish","type":"post","link":"https:\/\/dreness.com\/blog\/archives\/124","title":{"rendered":"Automator: Variable stacking"},"content":{"rendered":"<p>Shortly after discovering the existence of variables as real drag-n-droppable objects in Applescript Studio, I ran smack into a big limitation: the linear flow of an Automator workflow does not seem to allow for storing and recalling multiple values at once. Fortunately I was mistaken, as I discovered by accident while examining the &#8216;results&#8217; view of each workflow object as it received data from upstream objects. We begin with a touch of background.<\/p>\n<p>At first blush, the &#8220;Get Value of Variable&#8221; action seems like it can only really be used in conjunction with &#8220;Set Value of Variable&#8221;. You&#8217;d use &#8220;Set&#8221; to catch the output of some upstream object, and then store the value for later use.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-125\" title=\"set-value-of-variable\" src=\"http:\/\/www.dreness.com\/blog\/wp-content\/uploads\/2010\/02\/set-value-of-variable.png\" alt=\"set-value-of-variable\" width=\"578\" height=\"287\" srcset=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2010\/02\/set-value-of-variable.png 578w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2010\/02\/set-value-of-variable-300x148.png 300w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/p>\n<p>For those actions which do not support direct use of variable objects (e.g. &#8220;Name Single Item in Finder Item Names), one might instead try to pass the variable data as input, by connecting the input of a &#8220;Run Applescript&#8221; object to the output of &#8220;Get Value of Variable&#8221;, as long as you&#8217;re prepared to hand-write the stuff you need in Applescript.<\/p>\n<p>That&#8217;s all well and good, until you realize that you need to use more than one variable in your &#8220;Run Applescript&#8221; object. For example, let&#8217;s say you&#8217;re writing a file re-namer &#8211; you might need to pass in the file extension of the &#8216;old&#8217; file name, as well as the &#8216;new&#8217; file name. &#8220;Get Value of Variable&#8221; can only recall a single variable&#8217;s value.<\/p>\n<p>Here&#8217;s the trick: &#8220;Get Value of Variable&#8221; ALSO acts as a pass-through for whatever it receives on input, which allows you to stack multiple &#8220;Get Value&#8221;s, and then connect them to &#8220;Run Applescript&#8221;. In the &#8220;Run&#8221; object, the value of &#8216;input&#8217; will be a list of the values received. In the below example, I&#8217;ve got a pair of &#8220;Get&#8221;s under another object which outputs a file \/ folder reference, then all of that output is dumped into a &#8220;Run&#8221; object. Those values are then accessed in the standard fashion: &#8220;the first text item of input&#8221;, &#8220;the second item of input&#8221;, etc.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-129\" title=\"get-double-stack\" src=\"http:\/\/www.dreness.com\/blog\/wp-content\/uploads\/2010\/02\/get-double-stack.png\" alt=\"get-double-stack\" width=\"513\" height=\"662\" srcset=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2010\/02\/get-double-stack.png 513w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2010\/02\/get-double-stack-232x300.png 232w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/p>\n<p>Finally, the &#8220;Get Value&#8221; behavior of accepting input can be disabled by control-clicking on the &#8220;Get Value of Variable&#8221; title text on the object.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-134\" title=\"get-value-contextual-menu\" src=\"http:\/\/www.dreness.com\/blog\/wp-content\/uploads\/2010\/02\/get-value-contextual-menu.png\" alt=\"get-value-contextual-menu\" width=\"174\" height=\"199\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Shortly after discovering the existence of variables as real drag-n-droppable objects in Applescript Studio, I ran smack into a big limitation: the linear flow of an Automator workflow does not seem to allow for storing and recalling multiple values at &hellip; <a href=\"https:\/\/dreness.com\/blog\/archives\/124\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/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":[],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-bitbucket"],"_links":{"self":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":11,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":140,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/124\/revisions\/140"}],"wp:attachment":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}