<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>kenclark.me &#187; applescript</title>
	<atom:link href="http://kenclark.me/tag/applescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://kenclark.me</link>
	<description>a technology journal</description>
	<lastBuildDate>Sat, 01 Oct 2011 12:46:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='kenclark.me' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title><![CDATA[Brett Terpstra on Toggling and Hiding Apps via AppleScript →]]></title>
		<link><![CDATA[http://brettterpstra.com/quick-tip-applescript-application-toggle/]]></link>
		<comments>http://kenclark.me/2011/01/brett-terpstra-on-toggling-and-hiding-apps-via-applescript/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 14:00:00 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[Linked List]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[os x]]></category>

		<guid isPermaLink="false">http://kenclark.me/?p=2286</guid>
		<description><![CDATA[I always enjoy reading what other people are AppleScripting as it usually gives me some ideas about how to better use my Mac. I use LaunchBar as my application launcher, so Brett Terpstra's script didn't directly hit the sweet spot of fixing a problem I had, but it did get my thinking about what I do when I want to hide the current application.<a href="http://kenclark.me/2011/01/brett-terpstra-on-toggling-and-hiding-apps-via-applescript/" rel="bookmark" title="Permanent link to 'Brett Terpstra on Toggling and Hiding Apps via AppleScript'" class="glyph">∞ Permalink</a>
]]></description>
			<content:encoded><![CDATA[<p></p><p>I always enjoy reading what other people are AppleScripting as it usually gives me some ideas about how to better use my Mac. I use <a href="http://www.obdev.at/products/launchbar/index.html">LaunchBar</a> as my application launcher, so Brett Terpstra&#8217;s script didn&#8217;t directly hit the sweet spot of fixing a problem I had, but it did get me thinking about what I do when I want to hide the current application.</p>

<p>I didn&#8217;t have any tricks, so shortly after reading the post, I wrote this dead simple AppleScript to hide the frontmost app:</p>

<pre><code>tell application "System Events"
    set current_app to name of first process where frontmost is true
    set visible of process current_app to false
end tell
</code></pre>

<p>Just as I was about to assign this to a <a href="http://www.red-sweater.com/fastscripts/">FastScripts</a> keyboard shortcut, it occurred to me that I was probably over-thinking it and OS X had to already support this functionality in some way, right?</p>

<p>A Google search later confirmed it: <em>Cmd-H</em> hides the current app, and for bonus points, you have <em>Cmd-Option-H</em> which hides all apps <em>except</em> for the current app.</p>

<p>Two great keyboard shortcuts I was previously unaware of.  Thanks, Brett.  It all started with your post.</p>
<p><a href="http://kenclark.me/2011/01/brett-terpstra-on-toggling-and-hiding-apps-via-applescript/" rel="bookmark" title="Permanent link to 'Brett Terpstra on Toggling and Hiding Apps via AppleScript'" class="glyph">∞ Permalink</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2011/01/brett-terpstra-on-toggling-and-hiding-apps-via-applescript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>An AppleScript Function to Zero Pad a Value</title>
		<link>http://kenclark.me/2009/10/an-applescript-function-to-zero-pad-integers/</link>
		<comments>http://kenclark.me/2009/10/an-applescript-function-to-zero-pad-integers/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 03:44:26 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[All About Apple]]></category>
		<category><![CDATA[Mac OS X Automation]]></category>
		<category><![CDATA[applescript]]></category>

		<guid isPermaLink="false">http://www.kenclarksblog.com/?p=1264</guid>
		<description><![CDATA[An AppleScript function to zero-pad integers.]]></description>
			<content:encoded><![CDATA[<p></p><p>I wrote this subroutine tonight as I watched Game 5 of the ALCS.  It takes a number and a desired length and then zero pads it.</p>

<pre>on zero_pad(value, string_length)
    set string_zeroes to ""
    set digits_to_pad to string_length - (length of (value as string))
    if digits_to_pad &gt; 0 then
        repeat digits_to_pad times
            set string_zeroes to string_zeroes &amp; "0" as string
        end repeat
    end if
    set padded_value to string_zeroes &amp; value as string
    return padded_value
end zero_pad</pre>

<p>You could call it like this:</p>

<pre>set new_value to zero_pad(7, 3)</pre>

<p>&#8230;which would return a well-known secret agent&#8217;s alias:</p>

<pre>007</pre>

<p>Or you could call it like this:</p>

<pre>set month to zero_pad(month of (current date),2)</pre>

<p>&#8230;which for September would return a nicely zero-padded month value:</p>

<pre>09</pre>

<p>This worked exactly as I wanted it to, but if anyone out there has a more efficient way to do it I would love to see it.</p>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2009/10/an-applescript-function-to-zero-pad-integers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Testing for Missing Value in AppleScript</title>
		<link>http://kenclark.me/2009/10/testing-for-missing-value-in-applescript/</link>
		<comments>http://kenclark.me/2009/10/testing-for-missing-value-in-applescript/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 13:45:17 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[All About Apple]]></category>
		<category><![CDATA[Mac OS X Automation]]></category>
		<category><![CDATA[applescript]]></category>

		<guid isPermaLink="false">http://www.kenclarksblog.com/?p=1178</guid>
		<description><![CDATA[The other day I got temporarily stuck on an AppleScript I've been tinkering with because I could not figure out how to test for what I perceived as a "null" value.  I had set a variable to a property of a class and was getting the result "missing value".  Here's how I solved it.]]></description>
			<content:encoded><![CDATA[<p></p><p>Here&#8217;s a quick one for the folks who are learning AppleScript out there&#8230;</p>

<p>The other day I got temporarily stuck on an AppleScript I&#8217;ve been tinkering with because I could not figure out how to test for what I perceived as a &#8220;null&#8221; value.  I had set a variable to a property of a class and was getting the result &#8220;missing value&#8221;.</p>

<p>Here&#8217;s some example code that illustrates it:</p>

<pre>tell application "Finder" to set this_variable to the size of the desktop</pre>

<p>The result is:</p>

<pre>missing value</pre>

<p>At first, I didn&#8217;t anything of it.  I told myself, &#8220;Easy.  Just figure out how to test for a null value and keep moving.&#8221;  Then I stopped to think about it.  As far as I knew there was no isNull() or similar function in AppleScript.  I quickly checked my trusty <a href="http://www.amazon.com/gp/product/0321149319?ie=UTF8&amp;tag=keclsbl-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321149319">AppleScript 1-2-3</a><img style="border:none !important;margin:0px !important" src="http://www.assoc-amazon.com/e/ir?t=keclsbl-20&amp;l=as2&amp;o=1&amp;a=0321149319" border="0" alt="" width="1" height="1" /> book and couldn&#8217;t find anything about testing for null values.</p>

<p>So my next thought was, &#8220;OK.  This is just about you learning how to think in AppleScript.  What is the AppleScript way to do this?&#8221;  A couple seconds later, I was convinced I had it.  Using the example above, my next line was equivalent to:</p>

<pre>if (this_variable is equal to "") then
    display dialog "it worked"
end if</pre>

<p>Nope.  I thought I may have gotten the syntax wrong, so I played around with that for awhile, but it didn&#8217;t work.</p>

<p>Of course if you Google something long enough, you will probably find the answer, and I found it, but it did take a little more time than I expected.  The solution was not only right in front of me but is ridiculously simple.</p>

<p>This statement does exactly what I was trying to accomplish.</p>

<pre>if (this_variable is missing value) then
    display dialog "it worked"
end if</pre>

<p>In AppleScript, &#8220;missing value&#8221; is an <a title="Missing Value in AppleScript" href="http://developer.apple.com/mac/library/DOCUMENTATION/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_fundamentals.html#//apple_ref/doc/uid/TP40000983-CH218-SW44" target="_blank">AppleScript constant</a> and you can test for it.  Doh!  My brain got tracked in on &#8220;testing for null&#8221;, and I didn&#8217;t even consider that &#8220;missing value&#8221; was more than just an error message.  Bingo.  Lesson learned.</p>

<p>I know this is simple stuff, but these are the little stumbling blocks I am plowing through right now.  Hopefully this post will help another AppleScript newbie out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2009/10/testing-for-missing-value-in-applescript/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title><![CDATA[Great Examples of TaskPaper AppleScripts →]]></title>
		<link><![CDATA[http://www.hogbaysoftware.com/wiki/TaskPaperAppleScripts]]></link>
		<comments>http://kenclark.me/2009/10/great-examples-of-taskpaper-applescripts/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 11:19:10 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[All About Apple]]></category>
		<category><![CDATA[Linked List]]></category>
		<category><![CDATA[Mac OS X Automation]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[taskpaper]]></category>

		<guid isPermaLink="false">http://www.kenclarksblog.com/?p=1140</guid>
		<description><![CDATA[I've been taking a look at TaskPaper of late and stumbled across this page on their company wiki.  This is a gem.  It's like an AppleScript Dictionary on steroids for the application.<a href="http://kenclark.me/2009/10/great-examples-of-taskpaper-applescripts/" rel="bookmark" title="Permanent link to 'Great Examples of TaskPaper AppleScripts'" class="glyph">∞ Permalink</a>
]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;ve been trying out <a title="TaskPaper" href="http://www.hogbaysoftware.com/products/taskpaper" target="_blank">TaskPaper</a> of late and stumbled across this page on their company wiki.</p>

<p>This is a gem.  What a great resource for power users of the application.</p>
<p><a href="http://kenclark.me/2009/10/great-examples-of-taskpaper-applescripts/" rel="bookmark" title="Permanent link to 'Great Examples of TaskPaper AppleScripts'" class="glyph">∞ Permalink</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2009/10/great-examples-of-taskpaper-applescripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thinking in AppleScript</title>
		<link>http://kenclark.me/2009/10/thinking-in-applescript/</link>
		<comments>http://kenclark.me/2009/10/thinking-in-applescript/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 13:15:13 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[All About Apple]]></category>
		<category><![CDATA[Mac OS X Automation]]></category>
		<category><![CDATA[applescript]]></category>

		<guid isPermaLink="false">http://www.kenclarksblog.com/?p=1083</guid>
		<description><![CDATA[am starting to "think in AppleScript".  I question pretty much anything that I do that seems remotely time intensive or rote and ask myself, "can you script that?"   I am adding scripts to my "ideas list" faster than I'm able to write them at the moment.]]></description>
			<content:encoded><![CDATA[<p></p><pre>tell application "Ken"
   set new_applescript_ideas to every idea that hits me while I use my Mac
   try
       create_applescript(new_applescript_ideas)
   on error
      display dialog "Back to the drawing board..."
   end try
end tell</pre>

<p>If you are still reading after that geek-fest above, I have to say I am pretty impressed!   That pseudo-script however really expresses the shift that is going on inside my brain right now.  <a title="Learning Applescript One Script At at Time" href="2009/09/learning-applescript-one-script-at-a-time/">Learning AppleScript</a> has become a recent hobby of mine, and while I can&#8217;t give it eight hours a day, I am trying to get a couple hours here and there each week in order to improve my scripting chops.</p>

<p>What I&#8217;ve recognized is that sometime after the intial dozen or so hours of trying to figure out why this language is fairly easy to read but harder to write, you hit a breakthrough and start getting it.  Then, after you knock off <a title="Simple AppleScript" href="2009/09/an-applescript-to-move-screenshots-from-the-desktop/">a simple script</a> or two that actually does what you want, you get your second wind.</p>

<p>For me that second wind got me starting to &#8220;think in AppleScript&#8221;.  I look at what I&#8217;m doing on my Mac now with a much different perspective.  I question pretty much anything that I do that seems remotely time intensive or rote and ask myself, &#8220;can you script that?&#8221;   I am adding scripts to my &#8220;ideas list&#8221; faster than I&#8217;m able to write them at the moment.</p>

<p>Now it&#8217;s all about getting that other part of my brain, the one has to execute and write the scripts, to catch up with the part that is coming up with all of these scripting ideas.</p>

<p>It&#8217;s too bad that my newly acquired Applescript thinking super power can&#8217;t write a script to do that <img src='http://kenclark.me/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2009/10/thinking-in-applescript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Dropbox to Create a Yojimbo iPhone App</title>
		<link>http://kenclark.me/2009/10/use-dropbox-to-create-a-yojimbo-iphone-app/</link>
		<comments>http://kenclark.me/2009/10/use-dropbox-to-create-a-yojimbo-iphone-app/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 10:49:20 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[All About Apple]]></category>
		<category><![CDATA[Mac OS X Automation]]></category>
		<category><![CDATA[Working Smart]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[folder action]]></category>
		<category><![CDATA[yojimbo]]></category>

		<guid isPermaLink="false">http://www.kenclarksblog.com/?p=1000</guid>
		<description><![CDATA[This morning I read that DropBox announced their new iPhone app, and it occurred to me that you could set up the Dropbox iPhone app to clip images directly into Yojimbo with very minimal effort.  I was so pumped.  The lack of an iPhone app for Yojimbo was the reason I started using Evernote, so this was a total game changer]]></description>
			<content:encoded><![CDATA[<p></p><p>Yesterday I read that <a title="Dropbox Announces iPhone App" href="http://www.getdropbox.com/iphoneapp" target="_blank">DropBox announced their new iPhone app</a>, and it occurred to me that you could set up the Dropbox iPhone app to clip images directly into Yojimbo with very minimal effort.  I was so pumped.  This was a total game changer.</p>

<p>Here&#8217;s how to do it:</p>

<p>(Note:  I&#8217;m assuming that you have Yojimbo installed on your Mac and Dropbox installed on both your iPhone and Mac.  If not, download Dropbox <a title="DropBox" href="http://getdropbox.com" target="_blank">here</a> and Yojimbo <a title="Yojimbo" href="http://barebones.com/products/yojimbo/" target="_blank">here</a>.)</p>

<ol>
<li>On your Mac, create a new folder called &#8220;Clip to Yojimbo&#8221; in your Dropbox folder:</li>
</ol>

<p><img class="aligncenter size-full wp-image-1001" title="Clip to Yojimbo Folder in Dropbox" src="http://www.kenclarksblog.com/wp-content/uploads/2009/09/clip-to-yojimbo-folder-in-dropbox.png" alt="Clip to Yojimbo Folder in Dropbox" width="450" height="254" /></p>

<ol>
<li> Copy and past the below code into Script Editor.  This will become a folder action that runs anytime a file is added to the &#8220;Clip to Yojimbo&#8221; folder (note: you will have to <a title="Enable Folder Actions" href="http://www.simplehelp.net/2007/01/30/folder-actions-for-os-x-explained-with-real-world-examples/" target="_self">enable folder actions</a> if they are not already set up).  Save the script to your Mac&#8217;s Library/Scripts/Folder Actions folder as &#8220;import to Yojimbo&#8221; or whatever name you like.</li>
</ol>

<pre>on adding folder items to this_folder after receiving these_items
    repeat with x from 1 to the count of these_items
        set theFile to item x of these_items
        try
            tell application "Yojimbo"
                import theFile
            end tell
        end try
    end repeat
end adding folder items to</pre>

<p>Note for Scripters:  You can certainly get a little fancier with the Applescript, i.e. move the picture to an archive folder after the import is complete, etc. but this is all you need to get the basic import done.</p>

<ol>
<li> Assign the &#8220;import to Yojimbo&#8221; folder action to the &#8220;Clip to Yojimbo&#8221; folder.</li>
</ol>

<p><img class="aligncenter size-full wp-image-1002" title="Assign Yojimbo Folder Action" src="http://www.kenclarksblog.com/wp-content/uploads/2009/09/assign-yojimbo-folder-action.png" alt="Assign Yojimbo Folder Action" width="482" height="384" /></p>

<ol>
<li>That&#8217;s it.  Now it is time to test it out.  Go to your iPhone, go to DropBox and navigate to the &#8220;Clip to Yojimbo&#8221; folder.  Take a picture.</li>
</ol>

<p><img class="aligncenter size-full wp-image-1003" title="Clip A Photo With Dropbox on the iPhone" src="http://www.kenclarksblog.com/wp-content/uploads/2009/09/clip-photo-dropbox-iphone.jpg" alt="Clip A Photo With Dropbox on the iPhone" width="320" height="480" /></p>

<ol>
<li>If you are at your Mac, you will see the picture almost immediately show up in the Dropbox folder.</li>
</ol>

<p><img class="aligncenter size-full wp-image-1005" title="Clip to Yojimbo Folder with New Items" src="http://www.kenclarksblog.com/wp-content/uploads/2009/09/clip-to-yojimbo-with-items.png" alt="Clip to Yojimbo Folder with New Items" width="437" height="316" /></p>

<ol>
<li> A couple seconds later, it will import right into Yojimbo.</li>
</ol>

<p><img class="aligncenter size-full wp-image-1006" title="Succesful File Import into Yojimbo" src="http://www.kenclarksblog.com/wp-content/uploads/2009/09/files-imported-into-yojimbo.png" alt="Succesful File Import into Yojimbo" width="447" height="202" /></p>

<p>You&#8217;re done.  Pretty cool, right?  You can watch the whole process happen in real time on your Mac if you have the Finder open to the &#8220;Clip to Yojimbo&#8221; folder alongside an open Yojimbo window.  It is almost instantaneous.  The lack of an iPhone app for Yojimbo was the reason <a title="Evernote or Yojimbo?" href="evernote-or-yojimbo-finding-the-right-bucket-for-my-stuff/" target="_self">I started using Evernote</a>, so this is pretty exciting.   It probably just swung my decision pendulum back to using Yojimbo.</p>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2009/10/use-dropbox-to-create-a-yojimbo-iphone-app/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Learning Applescript&#8230; One Script At A Time</title>
		<link>http://kenclark.me/2009/09/learning-applescript-one-script-at-a-time/</link>
		<comments>http://kenclark.me/2009/09/learning-applescript-one-script-at-a-time/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 13:15:00 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[All About Apple]]></category>
		<category><![CDATA[Mac OS X Automation]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[folder actions]]></category>
		<category><![CDATA[growl]]></category>

		<guid isPermaLink="false">http://www.kenclarksblog.com/?p=799</guid>
		<description><![CDATA[I have been pushing myself of late to take my Mac knowledge to that next level, and as far as I am concerned the path to get there goes straight through Mac OS X's automation tools, and Applescript in particular.]]></description>
			<content:encoded><![CDATA[<p></p><p>I have been pushing myself of late to take my Mac knowledge to that next level, and as far as I am concerned the path to get there goes straight through Mac OS X&#8217;s automation tools, and Applescript in particular.</p>

<p>My strategy to learning Applescript is pretty simple.   I&#8217;ve armed myself with Sal Soghoian&#8217;s excellent book, <a href="http://www.amazon.com/gp/product/0321149319?ie=UTF8&amp;tag=keclsbl-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0321149319">AppleScript 1-2-3</a><img style="border:none !important;margin:0px !important" src="http://www.assoc-amazon.com/e/ir?t=keclsbl-20&amp;l=as2&amp;o=1&amp;a=0321149319" border="0" alt="" width="1" height="1" />, and I periodically assign myself small projects to script real world tasks.  Ironically enough, at least until I get a little more experienced, writing a script is not always the fastest or easiest way to get things done.  However, you&#8217;ve got to start somewhere and to paraphrase President Kennedy, we do things not because they are easy but because they are hard.</p>

<p>Several weeks ago I downloaded a trial of <a title="Hazel" href="http://www.noodlesoft.com/hazel.php" target="_blank">Hazel</a> after hearing many good things about it on various podcasts and blogs.  Hazel is an application that makes it easy to establish automated rules for folder management, and I had set up a Hazel rule that automatically moved screenshots from my desktop to a designated screenshots folder (<a title="Clean Up Your Mac" href="http://lifehacker.com/320951/set-up-a-self+cleaning-mac-with-hazel" target="_blank">thanks go out to Lifehacker for the idea</a>).  I quickly realized this was a perfect candidate for an Applescript project.  Everything Hazel was doing for me in this rule could be automated with Applescript, and it covered scripting tasks I&#8217;d never attempted before.</p>

<p>It sounded simple enough, yet it quickly introduced other choices for me to consider:  How do I tell if a file is really a PNG image versus a text file with a .png extension?  How do I handle a failed move operation?  What do I do if there is an unhandled error?  How do I notify a user of success or failure?  Should I use Growl?  How do I know if Growl is running?  Even though this was a very basic script, I couldn&#8217;t help but think of the parallels with what Brent Simmons discusses in his article, <a title="Anatomy of a Feature" href="http://inessential.com/2009/07/30/anatomy_of_a_feature" target="_blank">Anatomy of a Feature</a>.</p>

<p>Thinking through these questions were important &#8212; they created additional opportunities to learn.  By the time I was done I had picked up some good Applescript experience, to include:</p>

<ul>
    <li>scripting Folder Actions</li>
    <li>how and why to use Uniform Type Identifiers (UTI)</li>
    <li>why you should use System Events in Leopard / Snow Leopard instead of the &#8220;for info&#8221; command</li>
    <li><a title="How to Set Up Growl Notifications in Applescript" href="http://growl.info/documentation/applescript-support.php" target="_blank">how to set up Growl notifications via Applescript</a></li>
    <li>how to check if an application was running</li>
</ul>

<p>I&#8217;m now keeping a list of similar-sized scripting projects and doing my best to knock them off one by one.  While the going is sometimes slow and the projects are small in scope, each is steadily moving me along the path to become a better scripter.</p>

<p>BTW, here&#8217;s <a title="Applescript to Move Screenshots Off the Desktop" href="an-applescript-to-move-screenshots-from-the-desktop" target="_self">the script </a>(It may not seem like much, but trust me &#8212; it took me a little time to get there!).
<span style="font-family: monospace, 'Times New Roman', 'Bitstream Charter', Times, serif">
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2009/09/learning-applescript-one-script-at-a-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Applescript to Move Screenshots From the Desktop</title>
		<link>http://kenclark.me/2009/09/an-applescript-to-move-screenshots-from-the-desktop/</link>
		<comments>http://kenclark.me/2009/09/an-applescript-to-move-screenshots-from-the-desktop/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 13:10:04 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[All About Apple]]></category>
		<category><![CDATA[Mac OS X Automation]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[folder actions]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[UTI]]></category>

		<guid isPermaLink="false">http://www.kenclarksblog.com/?p=903</guid>
		<description><![CDATA[This Applescript is a folder action I wrote that moves screenshots taken with Mac OS X from my Desktop to a designated screenshots folder.]]></description>
			<content:encoded><![CDATA[<p></p><p>This Applescript is a folder action I wrote that moves screenshots taken with Mac OS X from my Desktop to a designated screenshots folder.  Setting it up requires that you <a title="Folder Actions Explained" href="http://www.simplehelp.net/2007/01/30/folder-actions-for-os-x-explained-with-real-world-examples/" target="_blank">enable folder actions and then assign this script as a folder action</a> to the Desktop folder.</p>

<p>I&#8217;m sure variations of this script have been written a million times over, but it was a minor success for me as I <a title="Learning Applescript" href="learning-applescript-one-script-at-a-time" target="_self">practice and learn Applescript</a>.</p>

<div style="border-width:1px;border-style:solid;padding:7px;background-color:#F0FFFF">If you found this page because you were looking for a snippet of code, there are some examples that you can take from the code below:
<ul>
    <li>how to check for a running process</li>
    <li>how to register an application with Growl and enable Growl notifications</li>
    <li>how to check for a Uniform Type Identifier (UTI) instead of checking for a given file type or file extension</li>
</ul>
</div>

<p>Here&#8217;s the code:</p>

<pre>on adding folder items to this_folder after receiving these_items

    -- Check to see if Growl is running
    tell application "System Events" to set growl_running to exists application process "GrowlHelperApp"

    -- Set the location of the new "screenshots folder"
    set screenshot_folder to "Ken's Macbook:Users:kenclark:Pictures:Screenshots:"

    -- Register these notifications with Growl
    if (growl_running) then
        tell application "GrowlHelperApp"
            set the all_notifications_list to {"File Move Complete", "Error"}
            set the enabled_notifications_list to {"File Move Complete", "Error"}
            register as application "Ken's Applescripts" all notifications all_notifications_list default notifications enabled_notifications_list icon of application "Script Editor"
        end tell
    end if

    tell application "Finder"
        repeat with x from 1 to the count of these_items
            set this_item to item x of these_items
            set item_name to name of this_item
            tell application "System Events" to set type_id to type identifier of this_item
            try
                if (type_id is "public.png") and (item_name starts with "Screen shot") then
                    move this_item to screenshot_folder
                    if (growl_running) then
                        tell application "GrowlHelperApp"
                            notify with name "File Move Complete" title "File Move Complete" description item_name &amp; " was successfully moved." application name "Ken's Applescripts"
                        end tell
                    end if
                end if
            on error error_message number error_number
                tell application "GrowlHelperApp"
                    notify with name "Error" title "File move failed" description error_message &amp; "
" &amp; error_number application name "Growl Applescript Test"
                end tell
            end try
        end repeat
    end tell
end adding folder items to</pre>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2009/09/an-applescript-to-move-screenshots-from-the-desktop/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Applescript: Count Characters in Clipboard for Twitter</title>
		<link>http://kenclark.me/2009/06/applescript-count-characters-in-clipboard-for-twitter/</link>
		<comments>http://kenclark.me/2009/06/applescript-count-characters-in-clipboard-for-twitter/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 19:47:28 +0000</pubDate>
		<dc:creator>Ken Clark</dc:creator>
				<category><![CDATA[All About Apple]]></category>
		<category><![CDATA[In the Cloud]]></category>
		<category><![CDATA[Mac OS X Automation]]></category>
		<category><![CDATA[Working Smart]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.kenclarksblog.com/2009/09/applescript-count-characters-in-clipboard-for-twitter/</guid>
		<description><![CDATA[Every now and then I need to copy text into my Twitter client app and need to know if I am bumping against the 140 character limit.  I wrote this quick applescript to simplify my life.  It counts the number of characters in the clipboard and subtracts that number from 140, so you know if [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Every now and then I need to copy text into my Twitter client app and need to know if I am bumping against the 140 character limit.  I wrote this quick applescript to simplify my life.  It counts the number of characters in the clipboard and subtracts that number from 140, so you know if your text is too long, too short, or right on target:</p>

<p><code>display dialog (”Total characters: “ &amp; (count (the clipboard)) &amp; “ “ &amp; “Remaining for Twitter: “ &amp; (140 - (count (the clipboard)))) with title “Character Count”</code></p>

<p>The best way to use this (outside of using a third-party app that can trigger Applescripts) is to save it to your ~/Library/Scripts folder after you have <a title="Enable Scripts Menu in OS X Menu Bar" href="http://www.usingmac.com/2007/10/16/reveal-applescript-menu-in-menu-bar" target="_blank">enabled the Scripts Menu in the OS X menu bar</a>, so you have access to it from any application.</p>
]]></content:encoded>
			<wfw:commentRss>http://kenclark.me/2009/06/applescript-count-characters-in-clipboard-for-twitter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

