Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AppleScript running under Cocoa - major speed issue



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?


Thanks for any and all thoughts!
Steve
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.