<?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: Scripting Bridge</title>
	<atom:link href="http://robnapier.net/blog/scripting-bridge-265/feed" rel="self" type="application/rss+xml" />
	<link>http://robnapier.net/blog/scripting-bridge-265</link>
	<description>Mac and iPhone, on the brain</description>
	<lastBuildDate>Thu, 02 Feb 2012 16:51:07 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bart</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-4392</link>
		<dc:creator>Bart</dc:creator>
		<pubDate>Tue, 21 Dec 2010 18:45:27 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-4392</guid>
		<description>&lt;p&gt;Thanks a lot for this tutorial. There&#039;s very little information about Scripting Bridge on the web even though it is much more user friendly in cocoa applications. Anyway, very useful information! Thanks.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks a lot for this tutorial. There&#8217;s very little information about Scripting Bridge on the web even though it is much more user friendly in cocoa applications. Anyway, very useful information! Thanks.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Pete Siemsen</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-2076</link>
		<dc:creator>Pete Siemsen</dc:creator>
		<pubDate>Wed, 04 Aug 2010 13:56:37 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-2076</guid>
		<description>&lt;p&gt;Rob,&lt;/p&gt;

&lt;p&gt;What would be the Scripting Bridge equivalent of the following AppleScript?&lt;/p&gt;

&lt;p&gt;set previousApp to the name of the current application
   -- some app gets activated here, raising is window(s) to the front
   tell application previousApp to activate&lt;/p&gt;

&lt;p&gt;My attempt, which probably just shows that a little knowledge is dangerous, partially works:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;NSString *systemEventsAppName = @&quot;com.apple.SystemEvents&quot;;
systemEventsApp = [SBApplication applicationWithBundleIdentifier:systemEventsAppName];
if (systemEventsApp == nil) {
    prependMessageToErrorChain(&quot;couldn&#039;t find an app named \&quot;%s\&quot;&quot;, [systemEventsAppName UTF8String]);
    return FAILURE;
}
if ( [systemEventsApp isRunning] ) {
    for (SystemEventsItem *systemEventsProcess in [systemEventsApp processes]) {
        NSDictionary *processProperties = [systemEventsProcess properties];
        NSString *processName    = [processProperties objectForKey:@&quot;name&quot;];
        NSString *processIsFront = [processProperties objectForKey:@&quot;frontmost&quot;];
        NSLog(@&quot;getPreviousApp: processName = \&quot;%@\&quot;, processIsFront = \&quot;%@\&quot;&quot;, processName, processIsFront);
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Although this identifies the app that has focus, it seems like this is the wrong approach - the loop through the processes is slow - it stops for a second or two on one of the processes.  Is there somewhere I can look for guidance?  A mailing list?&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;-- Pete&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Rob,</p>

<p>What would be the Scripting Bridge equivalent of the following AppleScript?</p>

<p>set previousApp to the name of the current application
   &#8212; some app gets activated here, raising is window(s) to the front
   tell application previousApp to activate</p>

<p>My attempt, which probably just shows that a little knowledge is dangerous, partially works:</p>

<p><pre><code>NSString *systemEventsAppName = @"com.apple.SystemEvents";
systemEventsApp = [SBApplication applicationWithBundleIdentifier:systemEventsAppName];
if (systemEventsApp == nil) {
    prependMessageToErrorChain("couldn't find an app named \"%s\"", [systemEventsAppName UTF8String]);
    return FAILURE;
}
if ( [systemEventsApp isRunning] ) {
    for (SystemEventsItem *systemEventsProcess in [systemEventsApp processes]) {
        NSDictionary *processProperties = [systemEventsProcess properties];
        NSString *processName    = [processProperties objectForKey:@"name"];
        NSString *processIsFront = [processProperties objectForKey:@"frontmost"];
        NSLog(@"getPreviousApp: processName = \"%@\", processIsFront = \"%@\"", processName, processIsFront);
    }
}
</code></pre></p>

<p>Although this identifies the app that has focus, it seems like this is the wrong approach &#8211; the loop through the processes is slow &#8211; it stops for a second or two on one of the processes.  Is there somewhere I can look for guidance?  A mailing list?</p>

<p>Thanks,</p>

<p>&#8211; Pete</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Napier</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-1857</link>
		<dc:creator>Rob Napier</dc:creator>
		<pubDate>Wed, 07 Jul 2010 20:36:44 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-1857</guid>
		<description>&lt;p&gt;&lt;a href=&quot;#comment-1854&quot; rel=&quot;nofollow&quot;&gt;@Pete Siemsen &lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Apparently, applicationWithBundleIdentifier doesn’t throw exceptions, and it NSLog’s on errors whether you like it or not.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Correct on both counts. This isn&#039;t particularly unusual in Cocoa. SBApplication is unusual in that it will raise exceptions (once created), and this turns out to be handy in my opinion. Because there are several pieces of Cocoa that will NSLog, I always freopen() STDOUT and STDERR to a log file in Release mode so that I can capture the failure when users send in problem reports.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><a href="#comment-1854" rel="nofollow">@Pete Siemsen </a></p>

<blockquote>
  <p>Apparently, applicationWithBundleIdentifier doesn’t throw exceptions, and it NSLog’s on errors whether you like it or not.</p>
</blockquote>

<p>Correct on both counts. This isn&#8217;t particularly unusual in Cocoa. SBApplication is unusual in that it will raise exceptions (once created), and this turns out to be handy in my opinion. Because there are several pieces of Cocoa that will NSLog, I always freopen() STDOUT and STDERR to a log file in Release mode so that I can capture the failure when users send in problem reports.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Pete Siemsen</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-1854</link>
		<dc:creator>Pete Siemsen</dc:creator>
		<pubDate>Wed, 07 Jul 2010 17:16:46 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-1854</guid>
		<description>&lt;p&gt;Thanks!  I used this article to write a ScriptingBridge app.  The app works, but I have one question: shouldn&#039;t the first line be outside the @try block?  If this line fails:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;MailApplication *mailApp = 
    [SBApplication applicationWithBundleIdentifier:@&quot;com.apple.mail&quot;];
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;...then mailApp will be set to nil.  To test it, I changed &quot;com.apple.mail&quot; to, like, &quot;com.apple.xxx&quot;.  As documented, mailApp was set to nil.  Also, a line like this appeared on standard out and in the Console:&lt;/p&gt;

&lt;p&gt;2010-07-07 11:11:59.026 myApp[1584:903] Can&#039;t find app with identifier com.apple.xxx&lt;/p&gt;

&lt;p&gt;Apparently, applicationWithBundleIdentifier doesn&#039;t throw exceptions, and it NSLog&#039;s on errors whether you like it or not.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks!  I used this article to write a ScriptingBridge app.  The app works, but I have one question: shouldn&#8217;t the first line be outside the @try block?  If this line fails:</p>

<p><pre><code>MailApplication *mailApp = 
    [SBApplication applicationWithBundleIdentifier:@"com.apple.mail"];
</code></pre></p>

<p>&#8230;then mailApp will be set to nil.  To test it, I changed &#8220;com.apple.mail&#8221; to, like, &#8220;com.apple.xxx&#8221;.  As documented, mailApp was set to nil.  Also, a line like this appeared on standard out and in the Console:</p>

<p>2010-07-07 11:11:59.026 myApp[1584:903] Can&#8217;t find app with identifier com.apple.xxx</p>

<p>Apparently, applicationWithBundleIdentifier doesn&#8217;t throw exceptions, and it NSLog&#8217;s on errors whether you like it or not.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: siemsen@ucar.edu</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-1847</link>
		<dc:creator>siemsen@ucar.edu</dc:creator>
		<pubDate>Wed, 07 Jul 2010 00:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-1847</guid>
		<description>&lt;p&gt;Excellent article, thanks!  I&#039;m using what I learned from it.  I have a working app, but I&#039;m having trouble with error handling.  Essentially, my code looks like this:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;@try {
    safari = [SBApplication applicationWithBundleIdentifier:@&quot;com.apple.Safari&quot;];
} @catch (NSException *exception) {
    NSLog(@&quot;Caught %@: %@&quot;, [exception name], [exception reason]);
}
// etc.
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;This works fine.  To test that the exception handling works, I change the name of the app to something nonexistent.  When I run it, an error like this is NSLog&#039;d:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;2010-07-06 18:00:06.647 myApp[1357:903] Can&#039;t find app with identifier com.apple.xxx
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;The &quot;catch&quot; doesn&#039;t execute.  I can check that &quot;safari&quot; isn&#039;t nil, but I apparently con&#039;t control that an error appears in the Console and on standard out.&lt;/p&gt;

&lt;p&gt;Should the try/catch work for this error?  Is there any way I can get control of the error?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Excellent article, thanks!  I&#8217;m using what I learned from it.  I have a working app, but I&#8217;m having trouble with error handling.  Essentially, my code looks like this:</p>

<p><pre><code>@try {
    safari = [SBApplication applicationWithBundleIdentifier:@"com.apple.Safari"];
} @catch (NSException *exception) {
    NSLog(@"Caught %@: %@", [exception name], [exception reason]);
}
// etc.
</code></pre></p>

<p>This works fine.  To test that the exception handling works, I change the name of the app to something nonexistent.  When I run it, an error like this is NSLog&#8217;d:</p>

<p><pre><code>2010-07-06 18:00:06.647 myApp[1357:903] Can't find app with identifier com.apple.xxx
</code></pre></p>

<p>The &#8220;catch&#8221; doesn&#8217;t execute.  I can check that &#8220;safari&#8221; isn&#8217;t nil, but I apparently con&#8217;t control that an error appears in the Console and on standard out.</p>

<p>Should the try/catch work for this error?  Is there any way I can get control of the error?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Napier</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-259</link>
		<dc:creator>Rob Napier</dc:creator>
		<pubDate>Thu, 24 Sep 2009 16:10:44 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-259</guid>
		<description>&lt;p&gt;I&#039;ve seen no easy way to create an HTML mail through Applescript. You can write the HTML to a file and read it in, but that&#039;s a lot of work. And I&#039;ve seen folks who pass keyboard events, but that&#039;s very fragile.&lt;/p&gt;

&lt;p&gt;There is a private property called &quot;htmlContent,&quot; but I&#039;ve never been able to read or write it. There&#039;s also a &quot;source&quot; property, but it&#039;s readonly. The mail headers are not modifiable on outgoing messages.&lt;/p&gt;

&lt;p&gt;I don&#039;t know if anyone has solved this problem in a good way.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;ve seen no easy way to create an HTML mail through Applescript. You can write the HTML to a file and read it in, but that&#8217;s a lot of work. And I&#8217;ve seen folks who pass keyboard events, but that&#8217;s very fragile.</p>

<p>There is a private property called &#8220;htmlContent,&#8221; but I&#8217;ve never been able to read or write it. There&#8217;s also a &#8220;source&#8221; property, but it&#8217;s readonly. The mail headers are not modifiable on outgoing messages.</p>

<p>I don&#8217;t know if anyone has solved this problem in a good way.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dalton Hamilton</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-258</link>
		<dc:creator>Dalton Hamilton</dc:creator>
		<pubDate>Thu, 24 Sep 2009 15:22:37 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-258</guid>
		<description>&lt;p&gt;Hi.  Excellent article.  I&#039;ve written a ScriptingBridge Cocoa app in Xcode and it works fine for text emails and attachments.  However, I want the attachment to show in the body of the email on Outlook email clients.  To do this, I need to convert the email to HTML by adding a header of &quot;Content-Type: text/html&quot;.   Do you know how to do this or know where I can find other classForScriptingClass objects -- specifically for headers?
Best Regard
Dalton Hamilton
Chapel Hill, NC&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi.  Excellent article.  I&#8217;ve written a ScriptingBridge Cocoa app in Xcode and it works fine for text emails and attachments.  However, I want the attachment to show in the body of the email on Outlook email clients.  To do this, I need to convert the email to HTML by adding a header of &#8220;Content-Type: text/html&#8221;.   Do you know how to do this or know where I can find other classForScriptingClass objects &#8212; specifically for headers?
Best Regard
Dalton Hamilton
Chapel Hill, NC</p>]]></content:encoded>
	</item>
	<item>
		<title>By: John Gallagher</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-40</link>
		<dc:creator>John Gallagher</dc:creator>
		<pubDate>Wed, 24 Jun 2009 13:23:29 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-40</guid>
		<description>&lt;p&gt;Thanks for this Rob. I tried to get Scripting Bridge working a few months ago and eventually gave up. I mention this because I was trying to convert an Applescript that ran perfectly, but I couldn&#039;t get certain properties with Scripting Bridge.&lt;/p&gt;

&lt;p&gt;It&#039;s a long, long time ago and I can&#039;t remember the specifics except that I was working with System Events, but it&#039;s worth noting that in some edge cases, Scripting Bridge won&#039;t allow you to access some areas that AppleScript does.&lt;/p&gt;

&lt;p&gt;So I eventually resigned myself to using a third party tool called AppScript - http://appscript.sourceforge.net/&lt;/p&gt;

&lt;p&gt;Hope this is helpful to someone else for who Scripting Bridge isn&#039;t suitable.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for this Rob. I tried to get Scripting Bridge working a few months ago and eventually gave up. I mention this because I was trying to convert an Applescript that ran perfectly, but I couldn&#8217;t get certain properties with Scripting Bridge.</p>

<p>It&#8217;s a long, long time ago and I can&#8217;t remember the specifics except that I was working with System Events, but it&#8217;s worth noting that in some edge cases, Scripting Bridge won&#8217;t allow you to access some areas that AppleScript does.</p>

<p>So I eventually resigned myself to using a third party tool called AppScript &#8211; <a href="http://appscript.sourceforge.net/" rel="nofollow">http://appscript.sourceforge.net/</a></p>

<p>Hope this is helpful to someone else for who Scripting Bridge isn&#8217;t suitable.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Napier</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-31</link>
		<dc:creator>Rob Napier</dc:creator>
		<pubDate>Sat, 13 Jun 2009 20:33:20 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-31</guid>
		<description>&lt;p&gt;Scripting Bridge does not exist on iPhone. The Mail.app you are importing here is a completely different application from the iPhone application, so wouldn&#039;t be helpful even if Scripting Bridge were available. You may be able to eventually get it compiling on Simulator because Simulator uses the Mac&#039;s version of Foundation, but it can&#039;t work on iPhone because iPhone doesn&#039;t provide an Applescript interface to other applications.&lt;/p&gt;

&lt;p&gt;The only interface 3rd party apps have to the Mail app on iPhone in 2.2 is the mailto: URL, which is limited, but all we really have.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Scripting Bridge does not exist on iPhone. The Mail.app you are importing here is a completely different application from the iPhone application, so wouldn&#8217;t be helpful even if Scripting Bridge were available. You may be able to eventually get it compiling on Simulator because Simulator uses the Mac&#8217;s version of Foundation, but it can&#8217;t work on iPhone because iPhone doesn&#8217;t provide an Applescript interface to other applications.</p>

<p>The only interface 3rd party apps have to the Mail app on iPhone in 2.2 is the mailto: URL, which is limited, but all we really have.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: mark e. barron</title>
		<link>http://robnapier.net/blog/scripting-bridge-265/comment-page-1#comment-29</link>
		<dc:creator>mark e. barron</dc:creator>
		<pubDate>Sat, 13 Jun 2009 17:05:55 +0000</pubDate>
		<guid isPermaLink="false">http://robnapier.net/blog/?p=265#comment-29</guid>
		<description>&lt;p&gt;I actually included the files named below
ScriptingBridge/SBApplication.h
main.h&lt;/p&gt;

&lt;p&gt;The pointy brackets were throwing the script.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I actually included the files named below
ScriptingBridge/SBApplication.h
main.h</p>

<p>The pointy brackets were throwing the script.</p>]]></content:encoded>
	</item>
</channel>
</rss>

