<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: AppleScript aaaaaargh!</title>
	<atom:link href="http://blakeseely.com/blog/archives/2005/12/05/applescript-aaaaaargh/feed/" rel="self" type="application/rss+xml" />
	<link>http://blakeseely.com/blog/archives/2005/12/05/applescript-aaaaaargh/</link>
	<description>If I could put reflection under this header, I would.</description>
	<pubDate>Mon, 08 Sep 2008 01:00:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Daniel Jalkut</title>
		<link>http://blakeseely.com/blog/archives/2005/12/05/applescript-aaaaaargh/#comment-279</link>
		<dc:creator>Daniel Jalkut</dc:creator>
		<pubDate>Mon, 05 Dec 2005 23:27:15 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/?p=48#comment-279</guid>
		<description>Hi Blake. It's definitely a slow, sometimes painful process. I've been learning for years and still feel vastly inferior to most scripters. 

First, I have nothing negative to say about the book you bought - I've never used it or seen it before. I bet it's fine. But I have never vouched for any other book on AppleScript besides Matt Neuberg's book. "AppleScript: the Definitive Guide." If I could only have one book on AppleScript, that would be it. In fact, it is it.

Here are some tips for, as you say, going from dictionary to language:

1. Always start at the top. Look at the "Application" class in the dictionary. It's tricky because it might be defined twice, as it is in iPhoto. Look for the definition inside the suite that looks most interesting. For instance, in iPhoto there is an application suite in the "iPhoto Suite". This seems to be where the goodies are (I haven't scripted iPhoto myself).

2. From the top, you can play with getting references to things on a very incremental basis. For instance, looking at the application class, I see that application "contains" albums. This means you can ask for that collection of items from AppleScript:

tell application "iPhoto"
   get albums
end

Run that in Script Editor and see what gets spit out in the returned value.  My strategy is to build up a script based on what I can get to "return" from the script. 

How you specific a particular object in AppleScript is not always the same from application to application. Often they will mention in the dictionary what the various forms of reference are: "by id," by name," etc. In this case the dictionary doesn't seem too helpful.

But if you look at the output of "get albums", you'll see a bunch of references to albums by name. The format of the reference as returned by the application is often what you can use yourself to specifically identify an item. 

So in my iPhoto library I have an album called "MiscFriends".  I ask iPhoto for the album (omitting tell application block):

get album "MiscFriends"

And it returns basically the same reference as I saw in the list of all albums. How do I get details about this?

You can look in the dictionary at the "album" class to see what elements and properties it (allegedly) contains.  Sometimes the dictionary is incomplete or unhelpful. You can sometimes get information directly from the applicatiion through AppleScript by asking for the properties of the object directly. In this case it's not too helpful, because there's only one property: name. 

The album class contains other elements, though.  So I can for instance ask for:

get first photo of album "MiscFriends"

And, looking again for information about the "photo" class in the dictionary, I see that I can ask for info about photos, too. Putting it all together, you could do something with a whose clause:

get first photo of album "MiscFriends" whose comment is "Wild Party"

Unfortunately I can't help you with the "make a new album" part. It's not immediately obvious to me either how this is done in iPhoto. Often you can use language like this:

set myAlbum to make new album at end of albums

But that doesn't seem to work here.</description>
		<content:encoded><![CDATA[<p>Hi Blake. It&#8217;s definitely a slow, sometimes painful process. I&#8217;ve been learning for years and still feel vastly inferior to most scripters. </p>
<p>First, I have nothing negative to say about the book you bought - I&#8217;ve never used it or seen it before. I bet it&#8217;s fine. But I have never vouched for any other book on AppleScript besides Matt Neuberg&#8217;s book. &#8220;AppleScript: the Definitive Guide.&#8221; If I could only have one book on AppleScript, that would be it. In fact, it is it.</p>
<p>Here are some tips for, as you say, going from dictionary to language:</p>
<p>1. Always start at the top. Look at the &#8220;Application&#8221; class in the dictionary. It&#8217;s tricky because it might be defined twice, as it is in iPhoto. Look for the definition inside the suite that looks most interesting. For instance, in iPhoto there is an application suite in the &#8220;iPhoto Suite&#8221;. This seems to be where the goodies are (I haven&#8217;t scripted iPhoto myself).</p>
<p>2. From the top, you can play with getting references to things on a very incremental basis. For instance, looking at the application class, I see that application &#8220;contains&#8221; albums. This means you can ask for that collection of items from AppleScript:</p>
<p>tell application &#8220;iPhoto&#8221;<br />
   get albums<br />
end</p>
<p>Run that in Script Editor and see what gets spit out in the returned value.  My strategy is to build up a script based on what I can get to &#8220;return&#8221; from the script. </p>
<p>How you specific a particular object in AppleScript is not always the same from application to application. Often they will mention in the dictionary what the various forms of reference are: &#8220;by id,&#8221; by name,&#8221; etc. In this case the dictionary doesn&#8217;t seem too helpful.</p>
<p>But if you look at the output of &#8220;get albums&#8221;, you&#8217;ll see a bunch of references to albums by name. The format of the reference as returned by the application is often what you can use yourself to specifically identify an item. </p>
<p>So in my iPhoto library I have an album called &#8220;MiscFriends&#8221;.  I ask iPhoto for the album (omitting tell application block):</p>
<p>get album &#8220;MiscFriends&#8221;</p>
<p>And it returns basically the same reference as I saw in the list of all albums. How do I get details about this?</p>
<p>You can look in the dictionary at the &#8220;album&#8221; class to see what elements and properties it (allegedly) contains.  Sometimes the dictionary is incomplete or unhelpful. You can sometimes get information directly from the applicatiion through AppleScript by asking for the properties of the object directly. In this case it&#8217;s not too helpful, because there&#8217;s only one property: name. </p>
<p>The album class contains other elements, though.  So I can for instance ask for:</p>
<p>get first photo of album &#8220;MiscFriends&#8221;</p>
<p>And, looking again for information about the &#8220;photo&#8221; class in the dictionary, I see that I can ask for info about photos, too. Putting it all together, you could do something with a whose clause:</p>
<p>get first photo of album &#8220;MiscFriends&#8221; whose comment is &#8220;Wild Party&#8221;</p>
<p>Unfortunately I can&#8217;t help you with the &#8220;make a new album&#8221; part. It&#8217;s not immediately obvious to me either how this is done in iPhoto. Often you can use language like this:</p>
<p>set myAlbum to make new album at end of albums</p>
<p>But that doesn&#8217;t seem to work here.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
