Re: Timing issues with Java executing AppleScript calling iTunes
Re: Timing issues with Java executing AppleScript calling iTunes
- Subject: Re: Timing issues with Java executing AppleScript calling iTunes
- From: Axel Luttgens <email@hidden>
- Date: Thu, 28 Feb 2008 16:42:23 +0100
Le 28 févr. 08 à 08:20, Zuhayr Khan a écrit :
Hi,
I'm cross-posting this to AppleScript and JavaDev as I'm not sure
where my issue lies.
I'm writing an application that needs to have iTunes import a file
into it's library.
The simple script I started with...
tell application "iTunes"
open "Macintosh HD:Users:zuhayrkhan:Music:Test.mp3"
end tell
...worked, but ended up playing the track - this isn't what I wanted.
I was hoping I could just add a "stop" call - but because open seems
to be asynchronous; this doesn't work.
[...]
So I implemented this testing iTunes' "player state" (see below),
and it worked fine (from within Script Editor anyway).
However; when compiling and invoking the script through Java - I get
some very strange results - you'll see from the code that I have a
lot of debug in there to see what's going on. I've seen situations
where I trigger the script from Java that seem to take a random time
to complete and also seem to be influenced by whether iTunes is
activated or not.. but then subsequent invocations work fine.
[...]
... when run from within Java:
[...]
06:14:27 about to delay:stopped
06:14:34 done delay:stopped
[...]
If anyone has any experience of this kind of behavior or has any
thoughts on what might be going on, I would greatly appreciate it.
If there's any more detail I can give, please let me know.
Difficult to tell without your full Java program.
Moreover, it seems I can't even enter the
repeat until playerState = "playing" ... end repeat
loop here when running the script in Script Editor.
So, just rough guesses...
Looks like you are encountering a problem around the "delay" command
when executed from a Java context.
That command always has been a bit special in AppleScript, so perhaps
could you try to replace
delay 0.1
by something like this
do shell script "php -r 'usleep(100000);'"
and see if you get the same behavior.
On the other hand, isn't the logics of your script rather convoluted?
If open "somefile" is going to always have iTunes playing the track
anyway, wouldn't the following approach be safer (pseudo-code):
open "somefile"
wait until state is playing
stop
or even:
open "somefile"
wait for some suitable fixed delay
stop
HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden