<?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/"
		>
<channel>
	<title>Comments on: Framework Friday: OSAKit</title>
	<atom:link href="http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/feed" rel="self" type="application/rss+xml" />
	<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit</link>
	<description>The personal weblog of Peter Hosey.</description>
	<lastBuildDate>Thu, 04 Mar 2010 07:09:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-232980</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Mon, 17 Nov 2008 22:30:42 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-232980</guid>
		<description>Joshua: Don&#039;t forget to link to the x-radar://problem/XXXXXX URL, so that any Apple employees who read this post can get to your bug easily.

If possible, it would also be nice if you&#039;d copy the report into &lt;a href=&quot;http://openradar.appspot.com/&quot; rel=&quot;nofollow&quot;&gt;OpenRadar&lt;/a&gt;, so that anyone can read it.</description>
		<content:encoded><![CDATA[<p>Joshua: Don't forget to link to the x-radar://problem/XXXXXX URL, so that any Apple employees who read this post can get to your bug easily.</p>
<p>If possible, it would also be nice if you'd copy the report into <a href="http://openradar.appspot.com/" rel="nofollow">OpenRadar</a>, so that anyone can read it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-232957</link>
		<dc:creator>Joshua</dc:creator>
		<pubDate>Mon, 17 Nov 2008 18:37:30 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-232957</guid>
		<description>Bug filed :-)</description>
		<content:encoded><![CDATA[<p>Bug filed :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-232674</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Sat, 15 Nov 2008 22:15:36 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-232674</guid>
		<description>Joshua: I don&#039;t know anything that isn&#039;t in the headers or the documentation. Neither of those said anything about it. (Of course, there is no documentation specifically for OSA Kit; the only material about OSA Kit in the documentation is that which &lt;em&gt;mentions&lt;/em&gt; OSA Kit.)

So, you should file a documentation bug. ☺</description>
		<content:encoded><![CDATA[<p>Joshua: I don't know anything that isn't in the headers or the documentation. Neither of those said anything about it. (Of course, there is no documentation specifically for OSA Kit; the only material about OSA Kit in the documentation is that which <em>mentions</em> OSA Kit.)</p>
<p>So, you should file a documentation bug. ☺</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-232631</link>
		<dc:creator>Joshua</dc:creator>
		<pubDate>Sat, 15 Nov 2008 15:08:59 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-232631</guid>
		<description>Can OSAKit be used on a secondary thread? That&#039;s the primary limitation of NSAppleScript for me, currently.</description>
		<content:encoded><![CDATA[<p>Can OSAKit be used on a secondary thread? That's the primary limitation of NSAppleScript for me, currently.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: has</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-232024</link>
		<dc:creator>has</dc:creator>
		<pubDate>Mon, 10 Nov 2008 22:14:20 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-232024</guid>
		<description>-[OSAScript executeHandlerWithName:arguments:error:] is working as advertised; the problem is that it&#039;s only suitable for calling AppleScript handlers whose names are user-defined identifiers. Handlers whose names are reserved keywords must be invoked using the equivalent raw AE codes. Here&#039;s a simple example to illustrate (it&#039;s modified from the CallAppleScriptHandler project in the &lt;a href=&quot;http://appscript.sourceforge.net/objc-appscript/index.html&quot; rel=&quot;nofollow&quot;&gt;objc-appscript svn repository&lt;/a&gt;):

&lt;code&gt;
#import &quot;Appscript/Appscript.h&quot;

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // Create AEMApplication object for building AEMEvents
    AEMApplication *app = [[AEMApplication alloc] init];

    // Create AEMCodecs object for unpacking script results
    AEMCodecs *codecs = [[AEMCodecs alloc] init];

    // Create &#039;aevtoapp&#039; (run) AEMEvent
    AEMEvent *evt = [app eventWithEventClass:kCoreEventClass
                                     eventID:kAEOpenApplication];

    // Build direct parameter for &#039;run&#039; event and add it to AEMEvent
    NSMutableArray *params = [NSMutableArray array];
    int i;
    for (i=1; i &lt; argc; i++)
        [params addObject: [NSString stringWithUTF8String: argv[i]]];
    [evt setParameter:params forKeyword:keyDirectObject];

    // Compile (or load) the AppleScript
    NSAppleScript *scpt = [[NSAppleScript alloc] initWithSource:
            @&quot;on run params\n&quot;
            @&quot;    return params as text\n&quot;
            @&quot;end run&quot;];

    // Get an NSAppleEventDescriptor from AEMEvent
    NSAppleEventDescriptor *evtDesc = [evt descriptor];

    // Send event to AppleScript
    NSDictionary *error = nil;
    NSAppleEventDescriptor *resultDesc = [scpt executeAppleEvent:evtDesc 
                                                           error:&amp;error];

    if (resultDesc) {
        // Unpack script result
        id res = [codecs unpack:resultDesc];
        NSLog(@&quot;Result = %@&quot;, res);
    } else
        NSLog(@&quot;Script error = %@&quot;, error);

    [scpt release];
    [codecs release];
    [app release];
    [pool release];
    return 0;
}
&lt;/code&gt;

Uses objc-appscript&#039;s AEM API for building events and converting ObjC values to NSAppleEventDescriptors and back. Plus NSAppleScript (which does indeed leak like a sieve on 10.4 and earlier, although I believe it&#039;s somewhat improved in 10.5) for executing scripts, but you could replace that with OSAScript easily enough if you wanted.

HTH 

has 
-- 
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net</description>
		<content:encoded><![CDATA[<p>-[OSAScript executeHandlerWithName:arguments:error:] is working as advertised; the problem is that it's only suitable for calling AppleScript handlers whose names are user-defined identifiers. Handlers whose names are reserved keywords must be invoked using the equivalent raw AE codes. Here's a simple example to illustrate (it's modified from the CallAppleScriptHandler project in the <a href="http://appscript.sourceforge.net/objc-appscript/index.html" rel="nofollow">objc-appscript svn repository</a>):</p>
<p><code><br />
#import "Appscript/Appscript.h"</code></p>
<p>int main (int argc, const char * argv[]) {<br />
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];</p>
<p>    // Create AEMApplication object for building AEMEvents<br />
    AEMApplication *app = [[AEMApplication alloc] init];</p>
<p>    // Create AEMCodecs object for unpacking script results<br />
    AEMCodecs *codecs = [[AEMCodecs alloc] init];</p>
<p>    // Create 'aevtoapp' (run) AEMEvent<br />
    AEMEvent *evt = [app eventWithEventClass:kCoreEventClass<br />
                                     eventID:kAEOpenApplication];</p>
<p>    // Build direct parameter for 'run' event and add it to AEMEvent<br />
    NSMutableArray *params = [NSMutableArray array];<br />
    int i;<br />
    for (i=1; i &lt; argc; i++)<br />
        [params addObject: [NSString stringWithUTF8String: argv[i]]];<br />
    [evt setParameter:params forKeyword:keyDirectObject];</p>
<p>    // Compile (or load) the AppleScript<br />
    NSAppleScript *scpt = [[NSAppleScript alloc] initWithSource:<br />
            @"on run params\n"<br />
            @"    return params as text\n"<br />
            @"end run"];</p>
<p>    // Get an NSAppleEventDescriptor from AEMEvent<br />
    NSAppleEventDescriptor *evtDesc = [evt descriptor];</p>
<p>    // Send event to AppleScript<br />
    NSDictionary *error = nil;<br />
    NSAppleEventDescriptor *resultDesc = [scpt executeAppleEvent:evtDesc<br />
                                                           error:&amp;error];</p>
<p>    if (resultDesc) {<br />
        // Unpack script result<br />
        id res = [codecs unpack:resultDesc];<br />
        NSLog(@"Result = %@", res);<br />
    } else<br />
        NSLog(@"Script error = %@", error);</p>
<p>    [scpt release];<br />
    [codecs release];<br />
    [app release];<br />
    [pool release];<br />
    return 0;<br />
}<br />
</p>
<p>Uses objc-appscript's AEM API for building events and converting ObjC values to NSAppleEventDescriptors and back. Plus NSAppleScript (which does indeed leak like a sieve on 10.4 and earlier, although I believe it's somewhat improved in 10.5) for executing scripts, but you could replace that with OSAScript easily enough if you wanted.</p>
<p>HTH </p>
<p>has<br />
--<br />
Control AppleScriptable applications from Python, Ruby and ObjC:<br />
<a href="http://appscript.sourceforge.net" rel="nofollow">http://appscript.sourceforge.net</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Kim</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-232010</link>
		<dc:creator>Paul Kim</dc:creator>
		<pubDate>Mon, 10 Nov 2008 19:50:26 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-232010</guid>
		<description>Actually, scratch that. It works even without conversion. But in any case, it does work on handlers besides the &quot;run&quot; one.</description>
		<content:encoded><![CDATA[<p>Actually, scratch that. It works even without conversion. But in any case, it does work on handlers besides the "run" one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Kim</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-232009</link>
		<dc:creator>Paul Kim</dc:creator>
		<pubDate>Mon, 10 Nov 2008 19:33:17 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-232009</guid>
		<description>I did manage to get your program working when using a non-&quot;run&quot; handler. One problem I found was that the args aren&#039;t being converted to NSAppleEventDescriptors. Try that and see if it works for you.</description>
		<content:encoded><![CDATA[<p>I did manage to get your program working when using a non-"run" handler. One problem I found was that the args aren't being converted to NSAppleEventDescriptors. Try that and see if it works for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-231998</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Mon, 10 Nov 2008 17:51:43 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-231998</guid>
		<description>&lt;p&gt;Jeff: No, your statements are wrong.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;to &lt;var&gt;handler-name&lt;/var&gt;&lt;/code&gt; is a valid way to start a handler. It&#039;s synonymous with &lt;code&gt;on &lt;var&gt;handler-name&lt;/var&gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;run&lt;/code&gt; is a reserved word: reserved for the name of the main handler (synonymous with just putting all your code at the top level, if you don&#039;t have any other handlers). That&#039;s what I wanted.&lt;/li&gt;
&lt;li&gt;You only need parentheses after the handler name if the handler is not &lt;code&gt;run&lt;/code&gt;. For the &lt;code&gt;run&lt;/code&gt; handler, the parentheses are optional.&lt;/li&gt;
&lt;li&gt;OSA, OSA Kit, and my program all accept text-only (.applescript) scripts, and treat them equally to how they treat compiled (.scpt) scripts. (How to prove this: Compile the script, then run my program on the result. You&#039;ll see the same result.)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I sincerely thank you for trying, but none of the advice you gave applies.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Jeff: No, your statements are wrong.</p>
<ol>
<li><code>to <var>handler-name</var></code> is a valid way to start a handler. It's synonymous with <code>on <var>handler-name</var></code>.</li>
<li><code>run</code> is a reserved word: reserved for the name of the main handler (synonymous with just putting all your code at the top level, if you don't have any other handlers). That's what I wanted.</li>
<li>You only need parentheses after the handler name if the handler is not <code>run</code>. For the <code>run</code> handler, the parentheses are optional.</li>
<li>OSA, OSA Kit, and my program all accept text-only (.applescript) scripts, and treat them equally to how they treat compiled (.scpt) scripts. (How to prove this: Compile the script, then run my program on the result. You'll see the same result.)</li>
</ol>
<p>I sincerely thank you for trying, but none of the advice you gave applies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Johnson</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-231996</link>
		<dc:creator>Jeff Johnson</dc:creator>
		<pubDate>Mon, 10 Nov 2008 17:30:45 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-231996</guid>
		<description>Heh, not sure what you mean by no. No it didn&#039;t work, or no you refuse to follow my advice?</description>
		<content:encoded><![CDATA[<p>Heh, not sure what you mean by no. No it didn't work, or no you refuse to follow my advice?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-231966</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Mon, 10 Nov 2008 08:03:05 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-231966</guid>
		<description>Jeff: No. The script is a valid AppleScript script (1–3), and both my application and OSA support .applescript files just fine (4). In fact, it shouldn&#039;t make any difference whether it&#039;s already-compiled or not, since OSA has supported plain-text scripts since Mac OS.</description>
		<content:encoded><![CDATA[<p>Jeff: No. The script is a valid AppleScript script (1–3), and both my application and OSA support .applescript files just fine (4). In fact, it shouldn't make any difference whether it's already-compiled or not, since OSA has supported plain-text scripts since Mac OS.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Johnson</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-231953</link>
		<dc:creator>Jeff Johnson</dc:creator>
		<pubDate>Mon, 10 Nov 2008 06:54:12 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-231953</guid>
		<description>Several issues: (1) The syntax is &quot;on&quot; rather than &quot;to&quot; for the handlers. (2) I think that &quot;run&quot; may be a reserved word, try &quot;my_run&quot;. (3) You need parentheses after the handler name, e.g., &quot;my_run()&quot;. (4) It doesn&#039;t seem to like the .applescript file extension, try .scpt.

&lt;code&gt;
on my_run()
    beep
end my_run
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Several issues: (1) The syntax is "on" rather than "to" for the handlers. (2) I think that "run" may be a reserved word, try "my_run". (3) You need parentheses after the handler name, e.g., "my_run()". (4) It doesn't seem to like the .applescript file extension, try .scpt.</p>
<p><code><br />
on my_run()<br />
    beep<br />
end my_run<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-231934</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Mon, 10 Nov 2008 01:28:15 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-231934</guid>
		<description>Jon Nathan: Sorry; I broke the link in changing it to the new filename.

I have now fixed it. Thanks for the report.</description>
		<content:encoded><![CDATA[<p>Jon Nathan: Sorry; I broke the link in changing it to the new filename.</p>
<p>I have now fixed it. Thanks for the report.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Nathan</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-231930</link>
		<dc:creator>Jon Nathan</dc:creator>
		<pubDate>Mon, 10 Nov 2008 01:04:00 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-231930</guid>
		<description>Thanks for the post, Peter. Getting a 404 on the download link for the OSAKit-osascript-1.0.1.tbz project, though.</description>
		<content:encoded><![CDATA[<p>Thanks for the post, Peter. Getting a 404 on the download link for the OSAKit-osascript-1.0.1.tbz project, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-231902</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Sun, 09 Nov 2008 21:21:18 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-231902</guid>
		<description>Jeff and Paul: Download the test app. I&#039;ve updated it to include a couple more sample scripts.

It definitely does &lt;em&gt;not&lt;/em&gt; work with the run handler. Calling &lt;code&gt;OSAGetHandlerNames&lt;/code&gt; shows the run handler as an Apple Event descriptor rather than a string descriptor, so that may be the problem there.

But I couldn&#039;t get it to work with a specific handler, either—I got the same result either way. (Yes, I did add a message to call that handler specifically.)</description>
		<content:encoded><![CDATA[<p>Jeff and Paul: Download the test app. I've updated it to include a couple more sample scripts.</p>
<p>It definitely does <em>not</em> work with the run handler. Calling <code>OSAGetHandlerNames</code> shows the run handler as an Apple Event descriptor rather than a string descriptor, so that may be the problem there.</p>
<p>But I couldn't get it to work with a specific handler, either—I got the same result either way. (Yes, I did add a message to call that handler specifically.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Kim</title>
		<link>http://boredzo.org/blog/archives/2008-11-09/framework-friday-osakit/comment-page-1#comment-231897</link>
		<dc:creator>Paul Kim</dc:creator>
		<pubDate>Sun, 09 Nov 2008 19:48:29 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/?p=698#comment-231897</guid>
		<description>-executeHandlerWithName:arguments:error: works fine for me. You just have to make sure that you lowercase the handler name (even if the actual handler name is mixed/upper case). This was also the case in the different categories people did to extend NSAppleScript to be able to call handler with arguments.</description>
		<content:encoded><![CDATA[<p>-executeHandlerWithName:arguments:error: works fine for me. You just have to make sure that you lowercase the handler name (even if the actual handler name is mixed/upper case). This was also the case in the different categories people did to extend NSAppleScript to be able to call handler with arguments.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.244 seconds -->
