<?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; growl</title>
	<atom:link href="http://kenclark.me/tag/growl/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>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>
	</channel>
</rss>

