Cocoa, iTunes, AppleScript - performance issue
Cocoa, iTunes, AppleScript - performance issue
- Subject: Cocoa, iTunes, AppleScript - performance issue
- From: Steve Cronin <email@hidden>
- Date: Thu, 13 Sep 2007 03:11:13 -0500
Folks;
I have a set of applescripts compiled into a .scpt resource which I
deploy as part of an application.
I have several utility type scripts which I call using something like
this:
NSDictionary *errorDict;
NSAppleEventDescriptor *thisResult;
NSAppleScript *myAppleScriptUtilities = [[NSAppleScript alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"ASUtilities" ofType:@"scpt"
inDirectory:@"Scripts"]] error:nil];
NSString *str = [myOSXUtilities launchApplication:@"com.apple.iTunes"];
if ([str isEqualToString:@"True"]) {
thisResult = [myAppleScriptUtilities executeAppleEvent:[self
callSub:@"applyGoodnessToTunes" params:
[NSAppleEventDescriptor descriptorWithString:theGoodness],
[NSAppleEventDescriptor descriptorWithString:trackID], nil]
error:&errorDict];
I have been pretty happy with this setup - I have several different
scripts (Finder & Mail) working.
Now I have begun to tinker with iTunes.
I have logging enabled in the applescripts so that I can debug and
then later so the customer can help me debug.
I have a simple script which writes some metadata to selected tracks:
set startTime to (current date)
my writeToLog("Tunes", "-- NEW SESSION --")
...
set pidC to length of myPIDList
repeat with j from 1 to pidC
tell application "iTunes"
my writeToLog("Tunes", "talking to iTunes - track count: " & pidC
as text)
set oldfi to fixed indexing
set fixed indexing to true
my writeToLog("Tunes", "iTunes fixed indexing set ")
...
set fixed indexing to oldfi
end tell
end repeat
set deltaTime to (current date) - startTime
my writeToLog("TagTunes", "ready to return - total time: " &
(deltaTime as text) & " secs")
Now, this snippet rocks when testing in Script Editor.
BUT when I run my Cocoa app and call out as above here is actual data
from the log:
Thursday, September 13, 2007 2:54:47 AM -- NEW SESSION --
Thursday, September 13, 2007 2:54:47 AM talking to iTunes - track
count: 5
Thursday, September 13, 2007 2:54:47 AM iTunes fixed indexing set
T h u r s d a y , S e p t e m b e r 1 3 , 2 0 0 7
2 : 5 4 : 4 7 A M t o p o f l o o p - - t r a c k
p i d : 9 3 D F 7 A D 6 7 5 F 0 7 E 3 C
T h u r s d a y , S e p t e m b e r 1 3 , 2 0 0 7
2 : 5 5 : 1 1 A M t r a c k p i d a c c e s s
c o m p l e t e d : 9 3 D F 7 A D 6 7 5 F 0 7 E 3 C
T h u r s d a y , S e p t e m b e r 1 3 , 2 0 0 7
2 : 5 5 : 1 1 A M r e a d y t o apply changes :
E v e r y t h i n g
Thursday, September 13, 2007 2:55:11 AM talking to iTunes - track
count: 5
Thursday, September 13, 2007 2:55:11 AM iTunes fixed indexing set
T h u r s d a y , S e p t e m b e r 1 3 , 2 0 0 7
2 : 5 5 : 1 1 A M t o p o f l o o p - - t r a c k
p i d : 9 3 D F 7 A D 6 7 5 F 0 7 E 4 0
T h u r s d a y , S e p t e m b e r 1 3 , 2 0 0 7
2 : 5 5 : 1 1 A M t r a c k p i d a c c e s s
c o m p l e t e d : 9 3 D F 7 A D 6 7 5 F 0 7 E 4 0
T h u r s d a y , S e p t e m b e r 1 3 , 2 0 0 7
2 : 5 5 : 1 1 A M r e a d y t o apply changes : E i g h t
E a s y S t e p s
Thursday, September 13, 2007 2:55:11 AM talking to iTunes - track
count: 5
....
As you can see there is a nearly 25 SECOND delay as the session gets
initiated.
I have seen the delay stated before the 'fixed index'...
but it always happens AND
it always happens only once and
it only happens at the start of the first time thru the loop.
It seems to me to be related to the first command given to the iTunes
tell block....
I have tried several different approaches but nothing has changed the
25 SECONDS!!
(BTW: this is a 1G MacBook running 10.4.10 and XCode 2.4.1)
I am not sure what to do next.
Does anyone out there have any ideas on what could be causing this?
I have not seen anything like this for the other AppleScripts I have
developed.
Thanks for any help!
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:
This email sent to email@hidden