<?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: Apple-Bug-Friday: iPhoto AppleScript Hang</title>
	<atom:link href="http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/feed/" rel="self" type="application/rss+xml" />
	<link>http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/</link>
	<description>If I could put reflection under this header, I would.</description>
	<pubDate>Wed, 07 Jan 2009 22:14:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: geowar</title>
		<link>http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/comment-page-1/#comment-103558</link>
		<dc:creator>geowar</dc:creator>
		<pubDate>Thu, 20 Nov 2008 16:15:24 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/#comment-103558</guid>
		<description>Instead of hardcoding a fixed delay time that could be too short or too long use a repeat while (importing) loop:

repeat while (importing)
delay 0.5 -- wait 1/2 second and try again
end repeat

This will loop until iPhoto is done importing and then continue.</description>
		<content:encoded><![CDATA[<p>Instead of hardcoding a fixed delay time that could be too short or too long use a repeat while (importing) loop:</p>
<p>repeat while (importing)<br />
delay 0.5 &#8212; wait 1/2 second and try again<br />
end repeat</p>
<p>This will loop until iPhoto is done importing and then continue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Didier</title>
		<link>http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/comment-page-1/#comment-1535</link>
		<dc:creator>Didier</dc:creator>
		<pubDate>Wed, 10 May 2006 13:26:48 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/#comment-1535</guid>
		<description>You should consider a bug as described here :
&lt;a href="http://homepage.mac.com/bwebster/Documentation/iPLM/pgs/faq_import_bug.html" rel="nofollow"&gt;Photos Won't Import Into iPhoto&lt;/a&gt;

I had the same problem, and finally fixed it this way :
&lt;code&gt;
property theFolder : "HardDisk:Library:Desktop Pictures:Nature:"
property album_name : "TestAlbum"

tell application "iPhoto"
	-- activate
	set exAlbum to exists album album_name
	if exAlbum then
		set myAlbum to album album_name
	else
		set myAlbum to (new album name album_name)
	end if
	select myAlbum
	set photoList to {}
	set thePhotos to list folder theFolder without invisibles
	repeat with eachItem in thePhotos
		set newPath to POSIX path of (theFolder &#38; eachItem)
		copy newPath to the end of photoList
	end repeat
	tell myAlbum
		import from (photoList)
	end tell
end tell
&lt;/code&gt;

Hope it helps.

D.S.</description>
		<content:encoded><![CDATA[<p>You should consider a bug as described here :<br />
<a href="http://homepage.mac.com/bwebster/Documentation/iPLM/pgs/faq_import_bug.html" rel="nofollow">Photos Won&#8217;t Import Into iPhoto</a></p>
<p>I had the same problem, and finally fixed it this way :<br />
<code><br />
property theFolder : "HardDisk:Library:Desktop Pictures:Nature:"<br />
property album_name : "TestAlbum"</p>
<p>tell application "iPhoto"<br />
	-- activate<br />
	set exAlbum to exists album album_name<br />
	if exAlbum then<br />
		set myAlbum to album album_name<br />
	else<br />
		set myAlbum to (new album name album_name)<br />
	end if<br />
	select myAlbum<br />
	set photoList to {}<br />
	set thePhotos to list folder theFolder without invisibles<br />
	repeat with eachItem in thePhotos<br />
		set newPath to POSIX path of (theFolder &amp; eachItem)<br />
		copy newPath to the end of photoList<br />
	end repeat<br />
	tell myAlbum<br />
		import from (photoList)<br />
	end tell<br />
end tell<br />
</code></p>
<p>Hope it helps.</p>
<p>D.S.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blake</title>
		<link>http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/comment-page-1/#comment-403</link>
		<dc:creator>blake</dc:creator>
		<pubDate>Tue, 07 Feb 2006 20:01:23 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/#comment-403</guid>
		<description>To be honest, it's not a very obvious bug. And the behavior has changed pretty significantly in iPhoto '06. I haven't tested it yet or updated the scripts, but I think the next code change to the scripts will need to detect which version of iPhoto a user has and do the right thing from there.</description>
		<content:encoded><![CDATA[<p>To be honest, it&#8217;s not a very obvious bug. And the behavior has changed pretty significantly in iPhoto &#8216;06. I haven&#8217;t tested it yet or updated the scripts, but I think the next code change to the scripts will need to detect which version of iPhoto a user has and do the right thing from there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Coyote Highway &#187; Blog Archive &#187; This is broken&#8230;</title>
		<link>http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/comment-page-1/#comment-402</link>
		<dc:creator>Coyote Highway &#187; Blog Archive &#187; This is broken&#8230;</dc:creator>
		<pubDate>Tue, 07 Feb 2006 19:15:04 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/#comment-402</guid>
		<description>[...] How exactly does this get past any reasonable testing process? The Apple quality-assurance process has gone downhill in a very serious way. [...]</description>
		<content:encoded><![CDATA[<p>[...] How exactly does this get past any reasonable testing process? The Apple quality-assurance process has gone downhill in a very serious way. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michaelv</title>
		<link>http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/comment-page-1/#comment-361</link>
		<dc:creator>michaelv</dc:creator>
		<pubDate>Thu, 12 Jan 2006 01:51:56 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/#comment-361</guid>
		<description>So on iPhoto 6, the script didn't hang iPhoto, it (the script) just returned an error at the point where it tried to do something with the not-yet-existent 'the_photo'.  I wanted to clarify that. 

As to the rest, __as I understand it__, the 'bug' (having to put delay statements everywhere) isn't really in iPhoto per se, but partly the way applescript works, and partly just timing -- it takes a while for the imported images to a) be imported, b) get properly 'registered' with the application and library.   Since importing happens asynchronously in iPhoto (so you can do other things while you're importing), i think the applescript 'import' command returns immediately.  This happens all the time in applescripts / apple events-- not just in iPhoto. 

Given something like:
  import from _somewhere to the_album
  set title of the first photo to "blah"

iPhoto starts importing, and the import is gonna take a few seconds or minutes or whatever.  But the script doesn't check to see if the import has completed, and the import command returns immediately. Since apple events such as those you're using don't wait around for a return value (i.e., "OK, I've imported the photos.. what now?"), the next line in the script gets executed without regard to the outcome of the first.   In this case iPhoto hasn't finished importing the images when the next line tries to do something with one of those images.  You could change this by adding in some checking, try blocks, etc. (maybe you do this already in your production scripts?)  There's some documentation (i think...?) on the apple developer site about error checking and handling exceptions, etc, in applescripts.  

Also, applescript is slow . . .  To me, it's kind of like "snail-mail" -- things take a while to get and respond to messages.  What's taking so !@#$ long!!???

In case it's not obvious, I'm no applescript expert.  I have a love-hate relationship with it-- mostly hate, really.  But I have had to use it in my work and have had to use some parts of iPhoto's (meager) script support.   I'd rather be writing cocoa code!
  
Hope that helps... you can ping me offline if you like.</description>
		<content:encoded><![CDATA[<p>So on iPhoto 6, the script didn&#8217;t hang iPhoto, it (the script) just returned an error at the point where it tried to do something with the not-yet-existent &#8216;the_photo&#8217;.  I wanted to clarify that. </p>
<p>As to the rest, __as I understand it__, the &#8216;bug&#8217; (having to put delay statements everywhere) isn&#8217;t really in iPhoto per se, but partly the way applescript works, and partly just timing &#8212; it takes a while for the imported images to a) be imported, b) get properly &#8216;registered&#8217; with the application and library.   Since importing happens asynchronously in iPhoto (so you can do other things while you&#8217;re importing), i think the applescript &#8216;import&#8217; command returns immediately.  This happens all the time in applescripts / apple events&#8211; not just in iPhoto. </p>
<p>Given something like:<br />
  import from _somewhere to the_album<br />
  set title of the first photo to &#8220;blah&#8221;</p>
<p>iPhoto starts importing, and the import is gonna take a few seconds or minutes or whatever.  But the script doesn&#8217;t check to see if the import has completed, and the import command returns immediately. Since apple events such as those you&#8217;re using don&#8217;t wait around for a return value (i.e., &#8220;OK, I&#8217;ve imported the photos.. what now?&#8221;), the next line in the script gets executed without regard to the outcome of the first.   In this case iPhoto hasn&#8217;t finished importing the images when the next line tries to do something with one of those images.  You could change this by adding in some checking, try blocks, etc. (maybe you do this already in your production scripts?)  There&#8217;s some documentation (i think&#8230;?) on the apple developer site about error checking and handling exceptions, etc, in applescripts.  </p>
<p>Also, applescript is slow . . .  To me, it&#8217;s kind of like &#8220;snail-mail&#8221; &#8212; things take a while to get and respond to messages.  What&#8217;s taking so !@#$ long!!???</p>
<p>In case it&#8217;s not obvious, I&#8217;m no applescript expert.  I have a love-hate relationship with it&#8211; mostly hate, really.  But I have had to use it in my work and have had to use some parts of iPhoto&#8217;s (meager) script support.   I&#8217;d rather be writing cocoa code!</p>
<p>Hope that helps&#8230; you can ping me offline if you like.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blake</title>
		<link>http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/comment-page-1/#comment-354</link>
		<dc:creator>blake</dc:creator>
		<pubDate>Wed, 11 Jan 2006 06:15:14 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/#comment-354</guid>
		<description>That's exactly what I wanted to hear - and that means the bug still exists in iPhoto '06. (I assume you tried this on a Macworld machine?!). Mugshot's code has a delay statement before each photo search statement - and that's the only thing that keeps it from hanging.</description>
		<content:encoded><![CDATA[<p>That&#8217;s exactly what I wanted to hear - and that means the bug still exists in iPhoto &#8216;06. (I assume you tried this on a Macworld machine?!). Mugshot&#8217;s code has a delay statement before each photo search statement - and that&#8217;s the only thing that keeps it from hanging.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michaelv</title>
		<link>http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/comment-page-1/#comment-353</link>
		<dc:creator>michaelv</dc:creator>
		<pubDate>Wed, 11 Jan 2006 00:34:45 +0000</pubDate>
		<guid isPermaLink="false">http://blakeseely.com/blog/archives/2006/01/06/apple-bug-friday-iphoto-applescript-hang/#comment-353</guid>
		<description>Works in iPhoto 6.0, with the caveat that I had to put a delay statement between the second and third lines in the tell statement (the one that starts with "import from.." and "set the_photo to...", otherwise I'd see an error that 'the variable the_photo is not defined'.
Hope that helps.</description>
		<content:encoded><![CDATA[<p>Works in iPhoto 6.0, with the caveat that I had to put a delay statement between the second and third lines in the tell statement (the one that starts with &#8220;import from..&#8221; and &#8220;set the_photo to&#8230;&#8221;, otherwise I&#8217;d see an error that &#8216;the variable the_photo is not defined&#8217;.<br />
Hope that helps.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
