Re: AppleScript running under Cocoa - major speed issue
Re: AppleScript running under Cocoa - major speed issue
- Subject: Re: AppleScript running under Cocoa - major speed issue
- From: Matt Neuburg <email@hidden>
- Date: Mon, 22 Oct 2007 10:33:40 -0700
- Thread-topic: AppleScript running under Cocoa - major speed issue
On Sat, 20 Oct 2007 10:46:22 -0500, Steve Cronin <email@hidden>
said:
>Folks;
>
>I have a Cocoa app that has some iPhoto integration.
>Since there is no Cocoa API for iPhoto, like there is for
>AddressBook, the only way I know to do this is through AppleScript.
>Any other ideas here would be appreciated....
>
>BTW: This is OS 10.4.10; Xcode 2.4.1; iPhoto 6.0.6; 2 GHz C2D
>
>The Cocoa app has a compiled AppleScript which I call into for the
>various handlers with the parameters I need.
>This is working well in every other case.
>For the record it looks like this:
> thisResult = [[[NSApp delegate] asEngine] executeAppleEvent:[ASCode
>callSub:@"getiPhotoImage" params:
> [NSAppleEventDescriptor descriptorWithString:path],
> nil] error:&errorDict];
>
>
>However I have a case where it is taking 25 seconds to execute a
>single AppleScript statement!
>This same statement has sub-second response when executed in the
>Script editor.
>If I simulate the Cocoa calls with various handlers in the Script
>Editor everything is fine - performance is fine!
>
>I have logging statements embedded in both Cocoa and AppleScript
>which have allowed me to hone in on the offending statement.
>
>The result is perfectly repeatable. Every time it takes 25 SECONDS
>to execute the following:
>[Cut and Paste this into a Script Editor - should work fine...(just
>change the myPath variable to make it work or fail]
>[You can also save it as a run-only application to see the
>performance is that incarnation...]
>
>set myPath to "/Users/SOMEUSERNAME/Pictures/iPhoto Library/Originals/
>2007/Roll 1/SOMEPICTURENAME.jpg"
>tell application "iPhoto"
> try
> set thisPhoto to first photo whose image path is myPath -- << THIS
>IS THE CULPRIT
> if thisPhoto exists then
> display dialog "'" & name of thisPhoto & "' was found"
> else
> display dialog "This branch will never occur"
> end if
> on error e number n
> if n = -2753 then
> display dialog "Requested photo was NOT found"
> else
> display dialog "Error: " & n & " - " & e
> end if
> end try
>end tell
>
>I know it may seem like an AppleScript issue but the shoddy
>performance is a ONLY when it is run underneath a Cocoa app so I am
>under the impression that there is something Cocoa-related which is
>causal.
>I don't believe any of our friends on the AppleScript list will have
>anything helpful, however I AM cross-posting to AppleScript list to
>see what I can find....
>
>Could anyone shed any light on what is going on here?
>Is there a hidden AppleScript feature like iTunes' 'fixed indexing'
>which might improve response times?
>Why does it work in Script Editor or as a AS run-only application?
Steve -
How do you know which line is "the culprit"? Could this be just an
assumption you're making? Could the problem actually be the compilation
time? I find it is necessary to "preflight" the AppleScript engine as the
app starts up in order to avoid delays the first time a script is run inside
a Cocoa app.
Also, this could be just a wild and crazy idea, but I would try changing
what you think is the troublesome line:
set thisPhoto to first photo whose image path is myPath
to this:
set thisPhoto to (get first photo whose image path is myPath)
Also, I would try doing a test where myPath is hard-coded into the script
rather than being passed in as a param (in other words, test it without the
callSub thing).
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
One of the 2007 MacTech Top 25: <http://tinyurl.com/2rh4pf>
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden