<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: tell application &#8220;YourGreatApp&#8221; NSAppleScript is here to save the day</title>
	<atom:link href="http://imlocation.wordpress.com/2007/04/21/nsapplescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/</link>
	<description>a look behind the curtain</description>
	<lastBuildDate>Mon, 19 Oct 2009 20:15:48 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Interfacing With (Hacking) iChat in Leopard &#171; IMLocation development log</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-288</link>
		<dc:creator>Interfacing With (Hacking) iChat in Leopard &#171; IMLocation development log</dc:creator>
		<pubDate>Tue, 12 Feb 2008 14:25:37 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-288</guid>
		<description>[...] hacks I&#8217;m about to discuss, check to see if existing frameworks , or iChat&#8217;s AppleScript interface, will do what you need. Any software update can break unsupported code in unpredictable ways at any [...]</description>
		<content:encoded><![CDATA[<p>[...] hacks I&#8217;m about to discuss, check to see if existing frameworks , or iChat&#8217;s AppleScript interface, will do what you need. Any software update can break unsupported code in unpredictable ways at any [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Better AppleScript Through Expressions &#171; IMLocation development log</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-82</link>
		<dc:creator>Better AppleScript Through Expressions &#171; IMLocation development log</dc:creator>
		<pubDate>Sat, 13 Oct 2007 17:04:57 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-82</guid>
		<description>[...] But it gets better. We can remove the run and try blocks as well, and just ignore any errors the interpreter complains about. That makes the script one line (ok, it&#8217;s wrapping in this poorly laid-out blog, but it&#8217;s still one line, down from 12 lines. Now it&#8217;s short enough to embed directly in Cocoa code with NSAppleScript. [...]</description>
		<content:encoded><![CDATA[<p>[...] But it gets better. We can remove the run and try blocks as well, and just ignore any errors the interpreter complains about. That makes the script one line (ok, it&#8217;s wrapping in this poorly laid-out blog, but it&#8217;s still one line, down from 12 lines. Now it&#8217;s short enough to embed directly in Cocoa code with NSAppleScript. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: (NS)AppleScript Sucks &#171; IMLocation development log</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-57</link>
		<dc:creator>(NS)AppleScript Sucks &#171; IMLocation development log</dc:creator>
		<pubDate>Mon, 24 Sep 2007 08:48:26 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-57</guid>
		<description>[...]   The NSAppleScript honeymoon is over. I don&#8217;t like AppleScript, I don&#8217;t like [...]</description>
		<content:encoded><![CDATA[<p>[...]   The NSAppleScript honeymoon is over. I don&#8217;t like AppleScript, I don&#8217;t like [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: imlocation</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-51</link>
		<dc:creator>imlocation</dc:creator>
		<pubDate>Thu, 06 Sep 2007 00:04:02 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-51</guid>
		<description>Elise,

Thanks for the reply, I have updated the article with your recommendations.  Also, the 3-line AppleScript I was using was unnecessarily long, this has been corrected.

Putting a large AppleScript in a separate source-file makes sense.  But in my opinion, for 1-5 line snippets, embedding the AppleScript right in the coca source code is the best way to go.  It&#039;s clear &lt;i&gt;exactly&lt;/i&gt; what the code does, because it&#039;s all right there -- no cross-referencing in separate .scpt files.  Executing a .scpt from your application&#039;s bundle is conceptually no different from executing a perl script, or any other type of script for that matter.  The beauty of NSAppleScript is that it lets you put AppleScript code right in your Cocoa code, which is very useful.  I know Apple does this, because the FrontRow executable has strings of AppleScript code inside it.

What you say about plugins and threads seems pretty close to what I was feeling when I first wrote this article.  AppleScript interfaces do seem to be very stable and a lot of them have been around longer then Coco interfaces.  But since then, few things have happened, and all of them have reduced the amount of AppleScript code I use.

I begun using threads more heavily, which made using NSAppleScript much more of a hassle.  Also, code that used to work, and was thread-safe except for NSAppleScript was suddenly broken.  This made me wary of using NSAppleScript in the future.  Hopefully things will be thread-safe in the future, but I&#039;m not holding my breath.

I learned about NSTasks, and have more experience with Cooca.  This has made other ways of getting things done, including buggy plugins + reverse-engineered interfaces, a bit more manageable for me.

I want to do things with a program that there is simply no way to do with a program&#039;s AppleScript interface.</description>
		<content:encoded><![CDATA[<p>Elise,</p>
<p>Thanks for the reply, I have updated the article with your recommendations.  Also, the 3-line AppleScript I was using was unnecessarily long, this has been corrected.</p>
<p>Putting a large AppleScript in a separate source-file makes sense.  But in my opinion, for 1-5 line snippets, embedding the AppleScript right in the coca source code is the best way to go.  It&#8217;s clear <i>exactly</i> what the code does, because it&#8217;s all right there &#8212; no cross-referencing in separate .scpt files.  Executing a .scpt from your application&#8217;s bundle is conceptually no different from executing a perl script, or any other type of script for that matter.  The beauty of NSAppleScript is that it lets you put AppleScript code right in your Cocoa code, which is very useful.  I know Apple does this, because the FrontRow executable has strings of AppleScript code inside it.</p>
<p>What you say about plugins and threads seems pretty close to what I was feeling when I first wrote this article.  AppleScript interfaces do seem to be very stable and a lot of them have been around longer then Coco interfaces.  But since then, few things have happened, and all of them have reduced the amount of AppleScript code I use.</p>
<p>I begun using threads more heavily, which made using NSAppleScript much more of a hassle.  Also, code that used to work, and was thread-safe except for NSAppleScript was suddenly broken.  This made me wary of using NSAppleScript in the future.  Hopefully things will be thread-safe in the future, but I&#8217;m not holding my breath.</p>
<p>I learned about NSTasks, and have more experience with Cooca.  This has made other ways of getting things done, including buggy plugins + reverse-engineered interfaces, a bit more manageable for me.</p>
<p>I want to do things with a program that there is simply no way to do with a program&#8217;s AppleScript interface.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elise van Looij</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-49</link>
		<dc:creator>Elise van Looij</dc:creator>
		<pubDate>Wed, 05 Sep 2007 11:07:55 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-49</guid>
		<description>BTW, Technote TN2084 describes adding a Run Script Build Phase to XCode, which is no longer necessary. Just add the Compile Applescripts Build Phase and all your applescript text files will be compilod to script files.

Also, the method described above for reading out the NSAppleEventDescriptor is a bit more complicated than is necessary most of the time. If you&#039;re expecting a single string, just use stringValue. So my version would be:

In an applescript text file called getMessage.applescript:

tell application ”iChat” 
    get status message
end tell


In a Cocoa / Objective-C class:

NSString *scriptPath = [[NSBundle mainBundle] pathForResource: @&quot;getMessage&quot;  ofType:  @&quot;scpt&quot; inDirectory: @&quot;Scripts&quot;];
//It doesn&#039;t matter in which group in XCode you put  getMessage.applescript, it will be compiled to Scripts/ getMessage.scpt in the bundle
NSDictionary *errorDict;
NSAppleScript *theScript = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath: scriptPath] error: nil];
NSAppleEventDescriptor *resultDescriptor = [theScript executeAndReturnError:&amp;errorDict];
NSLog([resultDescriptor stringValue]);</description>
		<content:encoded><![CDATA[<p>BTW, Technote TN2084 describes adding a Run Script Build Phase to XCode, which is no longer necessary. Just add the Compile Applescripts Build Phase and all your applescript text files will be compilod to script files.</p>
<p>Also, the method described above for reading out the NSAppleEventDescriptor is a bit more complicated than is necessary most of the time. If you&#8217;re expecting a single string, just use stringValue. So my version would be:</p>
<p>In an applescript text file called getMessage.applescript:</p>
<p>tell application ”iChat”<br />
    get status message<br />
end tell</p>
<p>In a Cocoa / Objective-C class:</p>
<p>NSString *scriptPath = [[NSBundle mainBundle] pathForResource: @&#8221;getMessage&#8221;  ofType:  @&#8221;scpt&#8221; inDirectory: @&#8221;Scripts&#8221;];<br />
//It doesn&#8217;t matter in which group in XCode you put  getMessage.applescript, it will be compiled to Scripts/ getMessage.scpt in the bundle<br />
NSDictionary *errorDict;<br />
NSAppleScript *theScript = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath: scriptPath] error: nil];<br />
NSAppleEventDescriptor *resultDescriptor = [theScript executeAndReturnError:&amp;errorDict];<br />
NSLog([resultDescriptor stringValue]);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elise van Looij</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-48</link>
		<dc:creator>Elise van Looij</dc:creator>
		<pubDate>Wed, 05 Sep 2007 08:33:59 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-48</guid>
		<description>Being an Applescripter moving into Cocoa programming, I confess I know very little of threads, be they safe or not. However, experience have taught me that using the various plugins and bridges that people cobble together, is definitely not the way to go. These plugins are rarely well thought out, often return unexpected results in strange formats, and are seldom supported, let alone upgraded. Applescript, on the other hand, is actively supported by Apple and various other parties and has improved dramatically over the past two years. So, if you want your Cocoa app to talk to other apps, Applescript is the way to go.
For the best way to acoomplish that, check out Apple&#039;s  &lt;a HREF=&quot;http://developer.apple.com/technotes/tn2006/tn2084.html&quot; rel=&quot;nofollow&quot;&gt;Technical note TN2084&lt;/A&gt; and &lt;a HREF=&quot;http://developer.apple.com/cocoa/applescriptforapps.html&quot; rel=&quot;nofollow&quot;&gt;Applescript and Cocoa&lt;/A&gt;. One tip you&#039;ll read there is that it&#039;s better to save your applescripts as scripts (add an Applescript Script File in XCode) and then call the compiled script in Cocoa.</description>
		<content:encoded><![CDATA[<p>Being an Applescripter moving into Cocoa programming, I confess I know very little of threads, be they safe or not. However, experience have taught me that using the various plugins and bridges that people cobble together, is definitely not the way to go. These plugins are rarely well thought out, often return unexpected results in strange formats, and are seldom supported, let alone upgraded. Applescript, on the other hand, is actively supported by Apple and various other parties and has improved dramatically over the past two years. So, if you want your Cocoa app to talk to other apps, Applescript is the way to go.<br />
For the best way to acoomplish that, check out Apple&#8217;s  <a HREF="http://developer.apple.com/technotes/tn2006/tn2084.html" rel="nofollow">Technical note TN2084</a> and <a HREF="http://developer.apple.com/cocoa/applescriptforapps.html" rel="nofollow">Applescript and Cocoa</a>. One tip you&#8217;ll read there is that it&#8217;s better to save your applescripts as scripts (add an Applescript Script File in XCode) and then call the compiled script in Cocoa.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: imlocation</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-28</link>
		<dc:creator>imlocation</dc:creator>
		<pubDate>Fri, 10 Aug 2007 09:19:19 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-28</guid>
		<description>More and more AppleScript code in IMLocation is getting replaced, because it is not powerful enough, clumsy, or not thread-safe.

I&#039;ve stopped using AppleScript to communicate with Adium -- instead I am writing an Adium plugin.  I&#039;m also using a private/unsupported interface to interface with iChat, because it is much more powerful then AppleScript.</description>
		<content:encoded><![CDATA[<p>More and more AppleScript code in IMLocation is getting replaced, because it is not powerful enough, clumsy, or not thread-safe.</p>
<p>I&#8217;ve stopped using AppleScript to communicate with Adium &#8212; instead I am writing an Adium plugin.  I&#8217;m also using a private/unsupported interface to interface with iChat, because it is much more powerful then AppleScript.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: has</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-3</link>
		<dc:creator>has</dc:creator>
		<pubDate>Sat, 21 Apr 2007 11:00:10 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-3</guid>
		<description>&quot;&quot;&quot;Now I am the first to admit that a well-written Objective-C library trumps duck-taping one language on-top of another.&quot;&quot;&quot;

If you&#039;re interested, there&#039;s a third-party Apple event bridge currently in development for ObjC, allowing you to skip AppleScript and talk to applications directly:

http://appscript.sourceforge.net/objc-appscript.html

e.g. To get iChat&#039;s status message:

&lt;code&gt;
// Generate glue: osaglue IC iChat
OSErr err = noErr;
ICApplication *iChat = [[ICApplication alloc] initWithName: @&quot;iChat.app&quot;];
ICGetCommand *getStatusCmd = [[iChat statusMessage] get];
NSString *statusMessage = [getStatusCmd send];
if (statusMessage == nil) err = [getStatusCmd errorNumber];
&lt;/code&gt;

HTH</description>
		<content:encoded><![CDATA[<p>&#8220;&#8221;"Now I am the first to admit that a well-written Objective-C library trumps duck-taping one language on-top of another.&#8221;"&#8221;</p>
<p>If you&#8217;re interested, there&#8217;s a third-party Apple event bridge currently in development for ObjC, allowing you to skip AppleScript and talk to applications directly:</p>
<p><a href="http://appscript.sourceforge.net/objc-appscript.html" rel="nofollow">http://appscript.sourceforge.net/objc-appscript.html</a></p>
<p>e.g. To get iChat&#8217;s status message:</p>
<p><code><br />
// Generate glue: osaglue IC iChat<br />
OSErr err = noErr;<br />
ICApplication *iChat = [[ICApplication alloc] initWithName: @"iChat.app"];<br />
ICGetCommand *getStatusCmd = [[iChat statusMessage] get];<br />
NSString *statusMessage = [getStatusCmd send];<br />
if (statusMessage == nil) err = [getStatusCmd errorNumber];<br />
</code></p>
<p>HTH</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: imlocation</title>
		<link>http://imlocation.wordpress.com/2007/04/21/nsapplescript/#comment-2</link>
		<dc:creator>imlocation</dc:creator>
		<pubDate>Sat, 21 Apr 2007 02:16:42 +0000</pubDate>
		<guid isPermaLink="false">http://imlocation.wordpress.com/2007/04/21/tell-application-yourgreatapp-nsapplescript-is-here-to-save-the-day/#comment-2</guid>
		<description>Sorry about the blue AppleScript code-snippits, I know they look just like links.  Unfortunately that&#039;s how ScriptEditor colors AppleScript code by default.</description>
		<content:encoded><![CDATA[<p>Sorry about the blue AppleScript code-snippits, I know they look just like links.  Unfortunately that&#8217;s how ScriptEditor colors AppleScript code by default.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
