<?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: Calling Applescript from Perl</title>
	<atom:link href="http://porkrind.org/missives/calling-applescript-from-perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://porkrind.org/missives/calling-applescript-from-perl/</link>
	<description>Portal For The Masses</description>
	<lastBuildDate>Thu, 26 Jan 2012 00:00:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Caravan</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-384</link>
		<dc:creator>Caravan</dc:creator>
		<pubDate>Thu, 10 Nov 2011 15:21:54 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-384</guid>
		<description>I see exactly the same from Data::Dumper

&lt;pre&gt;$VAR1 = [
          &#039;osascript&#039;,
          &#039;-e&#039;,
          &#039;tell application &quot;Finder&quot;
 display dialog &quot;Hello&quot;
 end tell&#039;
        ];
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I see exactly the same from Data::Dumper</p>
<pre>$VAR1 = [
          'osascript',
          '-e',
          'tell application "Finder"
 display dialog "Hello"
 end tell'
        ];
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-383</link>
		<dc:creator>david</dc:creator>
		<pubDate>Thu, 10 Nov 2011 15:16:51 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-383</guid>
		<description>Caravan, try adding this to your script:
&lt;pre&gt;use Data::Dumper;
sub osascript($) { print Dumper([&#039;osascript&#039;, map { (&#039;-e&#039;, $_) } split(/\r/, $_[0])]); }
&lt;/pre&gt;

When I run it I get:

&lt;pre&gt;$VAR1 = [
          &#039;osascript&#039;,
          &#039;-e&#039;,
          &#039;tell application &quot;Finder&quot;
display dialog &quot;Hello&quot;
end tell&#039;
        ];
&lt;/pre&gt;

That passes the newlines embedded in the command line (which apparently works). But it makes the whole map/split part pointless (since there are no &#039;\r&#039; chars in the string to split on). At that point you may as well just do:

&lt;pre&gt;system(&#039;osascript&#039;, &#039;-e&#039;,
&#039;tell application &quot;Finder&quot;
display dialog &quot;Hello&quot;
end tell&#039;)
&lt;/pre&gt;

I haven&#039;t seen Mac::Glue before. It looks cool. I don&#039;t have a problem with Apple Events per se—I like the idea of universal API for applications. I just don&#039;t like AppleScript itself. The natural language part of it never set well with me—the whole thing feels hacky. The idea of elevating AppleEvents to native (and fairly idiomatic) Perl is a good one.</description>
		<content:encoded><![CDATA[<p>Caravan, try adding this to your script:</p>
<pre>use Data::Dumper;
sub osascript($) { print Dumper(['osascript', map { ('-e', $_) } split(/\r/, $_[0])]); }
</pre>
<p>When I run it I get:</p>
<pre>$VAR1 = [
          'osascript',
          '-e',
          'tell application "Finder"
display dialog "Hello"
end tell'
        ];
</pre>
<p>That passes the newlines embedded in the command line (which apparently works). But it makes the whole map/split part pointless (since there are no &#8216;\r&#8217; chars in the string to split on). At that point you may as well just do:</p>
<pre>system('osascript', '-e',
'tell application "Finder"
display dialog "Hello"
end tell')
</pre>
<p>I haven&#8217;t seen Mac::Glue before. It looks cool. I don&#8217;t have a problem with Apple Events per se—I like the idea of universal API for applications. I just don&#8217;t like AppleScript itself. The natural language part of it never set well with me—the whole thing feels hacky. The idea of elevating AppleEvents to native (and fairly idiomatic) Perl is a good one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Caravan</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-381</link>
		<dc:creator>Caravan</dc:creator>
		<pubDate>Thu, 10 Nov 2011 14:06:41 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-381</guid>
		<description>Hi David,

I didn&#039;t really think that one through.  I&#039;m working on BBEdit 9.6.3 and I have line endings set to Unix (LF) but what is actually in my script is \r. My Perl scripts created on this work on both OSX and various flavours of linux.

The reason I happened upon your page was because I&#039;m doing a project using Mac::Glue. If you are not keen on Applescript or you want to have access to Perl&#039;s text processing power and  massive back catalogue of modules, including powerful encryption Mac::Glue is brilliant. Mac::Glue is a Perl Module that allows you to Control Mac apps with Apple event terminology from Perl. 

You can write a small Applescript that runs your Perl script all it has to say is:

do shell script &quot;perl /pathto/perlscript.pl&quot;

Your Perl script can then do anything and everything that a Perl script can do and then tell a Mac application to do something with the result.</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>I didn&#8217;t really think that one through.  I&#8217;m working on BBEdit 9.6.3 and I have line endings set to Unix (LF) but what is actually in my script is \r. My Perl scripts created on this work on both OSX and various flavours of linux.</p>
<p>The reason I happened upon your page was because I&#8217;m doing a project using Mac::Glue. If you are not keen on Applescript or you want to have access to Perl&#8217;s text processing power and  massive back catalogue of modules, including powerful encryption Mac::Glue is brilliant. Mac::Glue is a Perl Module that allows you to Control Mac apps with Apple event terminology from Perl. </p>
<p>You can write a small Applescript that runs your Perl script all it has to say is:</p>
<p>do shell script &#8220;perl /pathto/perlscript.pl&#8221;</p>
<p>Your Perl script can then do anything and everything that a Perl script can do and then tell a Mac application to do something with the result.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-380</link>
		<dc:creator>david</dc:creator>
		<pubDate>Thu, 10 Nov 2011 12:19:16 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-380</guid>
		<description>Caravan, you changed the \n to \r, which means your script doesn&#039;t have unix end-of-line characters. &#039;od -c &lt;i&gt;thescript.pl&lt;/i&gt;&#039; to check your end of lines. Normally Mac OS X text files use unix-style &#039;\n&#039; but if you were editing on an old Mac program (carbon based, from the pre-OS X days) then it might use the old Mac OS 9 style &#039;\r&#039; end-of-lines.

To completely fix it you could also do:
&lt;pre&gt;sub osascript($) { system ‘osascript’, map { (‘-e’, $_) } split(/[\r\n]+/, $_[0]); } 
&lt;/pre&gt;
which would handle &#039;\n&#039; (unix), &#039;\r&#039; (old-mac) and &#039;\r\n&#039; (windows) eols. It would also skip blank lines which is probably good too (-e &#039;&#039; would be pointless).</description>
		<content:encoded><![CDATA[<p>Caravan, you changed the \n to \r, which means your script doesn&#8217;t have unix end-of-line characters. &#8216;od -c <i>thescript.pl</i>&#8216; to check your end of lines. Normally Mac OS X text files use unix-style &#8216;\n&#8217; but if you were editing on an old Mac program (carbon based, from the pre-OS X days) then it might use the old Mac OS 9 style &#8216;\r&#8217; end-of-lines.</p>
<p>To completely fix it you could also do:</p>
<pre>sub osascript($) { system ‘osascript’, map { (‘-e’, $_) } split(/[\r\n]+/, $_[0]); }
</pre>
<p>which would handle &#8216;\n&#8217; (unix), &#8216;\r&#8217; (old-mac) and &#8216;\r\n&#8217; (windows) eols. It would also skip blank lines which is probably good too (-e &#8221; would be pointless).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Caravan</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-379</link>
		<dc:creator>Caravan</dc:creator>
		<pubDate>Thu, 10 Nov 2011 11:15:36 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-379</guid>
		<description>This works on OS X 10.5.8 for me.

&lt;pre&gt;#!/usr/bin/perl

sub osascript($) { system &#039;osascript&#039;, map { (&#039;-e&#039;, $_) } split(/\r/, $_[0]); } 
 
&amp;osascript (
 &#039;tell application &quot;Finder&quot;
 display dialog &quot;Hello&quot;
 end tell&#039;
)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>This works on OS X 10.5.8 for me.</p>
<pre>#!/usr/bin/perl

sub osascript($) { system 'osascript', map { ('-e', $_) } split(/\r/, $_[0]); } 

&amp;osascript (
 'tell application "Finder"
 display dialog "Hello"
 end tell'
)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-371</link>
		<dc:creator>Kurt</dc:creator>
		<pubDate>Tue, 11 Oct 2011 15:23:19 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-371</guid>
		<description>Ah-HA!

Turns out this is an error from requiring &quot;user interaction&quot; that  can be resolved with:

  tell application &quot;AppleScript Runner&quot;
  display dialog &quot;it works!&quot;
  end</description>
		<content:encoded><![CDATA[<p>Ah-HA!</p>
<p>Turns out this is an error from requiring &#8220;user interaction&#8221; that  can be resolved with:</p>
<p>  tell application &#8220;AppleScript Runner&#8221;<br />
  display dialog &#8220;it works!&#8221;<br />
  end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-370</link>
		<dc:creator>Kurt</dc:creator>
		<pubDate>Tue, 11 Oct 2011 15:02:29 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-370</guid>
		<description>Does not work under OS X 10.5.8.  Just goes away and never comes back.

This isn&#039;t surprising, since the same applescript code exhibits the same behavior when run from script editor.

However, running just: &lt;b&gt;display dialog &quot;Hello&quot; &lt;/b&gt;from Script Editor gives the desired results.

Unfortunately, trying to do the same from perl using the code above just generates the following error:

osascript(41994) malloc: *** error for object 0xa1b1c1d3: Non-aligned pointer being freed
*** set a breakpoint in malloc_error_break to debug
2:24: execution error: No user interaction allowed. (-1713)

Any insight?</description>
		<content:encoded><![CDATA[<p>Does not work under OS X 10.5.8.  Just goes away and never comes back.</p>
<p>This isn&#8217;t surprising, since the same applescript code exhibits the same behavior when run from script editor.</p>
<p>However, running just: <b>display dialog &#8220;Hello&#8221; </b>from Script Editor gives the desired results.</p>
<p>Unfortunately, trying to do the same from perl using the code above just generates the following error:</p>
<p>osascript(41994) malloc: *** error for object 0xa1b1c1d3: Non-aligned pointer being freed<br />
*** set a breakpoint in malloc_error_break to debug<br />
2:24: execution error: No user interaction allowed. (-1713)</p>
<p>Any insight?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-364</link>
		<dc:creator>david</dc:creator>
		<pubDate>Sat, 27 Aug 2011 10:30:29 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-364</guid>
		<description>You&#039;re right, the backslash was missing--probably from when I converted from Textmate to Wordpress. I&#039;ve fixed it. Thanks!</description>
		<content:encoded><![CDATA[<p>You&#8217;re right, the backslash was missing&#8211;probably from when I converted from Textmate to WordPress. I&#8217;ve fixed it. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Cronin</title>
		<link>http://porkrind.org/missives/calling-applescript-from-perl/comment-page-1/#comment-363</link>
		<dc:creator>Patrick Cronin</dc:creator>
		<pubDate>Sat, 27 Aug 2011 10:18:43 +0000</pubDate>
		<guid isPermaLink="false">http://porkrind.org/missives2/?p=17#comment-363</guid>
		<description>Thanks for the sub! It&#039;s working nicely in a script to add photos to certain albums in iPhoto based on their EXIF data. The regex in the post is appearing on your site like /n/ and not /\n/ (the backslash is missing). It wasn&#039;t working for me for a bit, and then I realized I was splitting on the letter n, and not newline characters. All set now, and thanks for doing the leg work!</description>
		<content:encoded><![CDATA[<p>Thanks for the sub! It&#8217;s working nicely in a script to add photos to certain albums in iPhoto based on their EXIF data. The regex in the post is appearing on your site like /n/ and not /\n/ (the backslash is missing). It wasn&#8217;t working for me for a bit, and then I realized I was splitting on the letter n, and not newline characters. All set now, and thanks for doing the leg work!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- This Quick Cache file was built for (  porkrind.org/missives/calling-applescript-from-perl/feed/ ) in 0.12155 seconds, on Feb 9th, 2012 at 11:06 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 12:06 pm UTC -->
