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: Zuhayr Khan <email@hidden>
- Date: Fri, 29 Feb 2008 06:31:24 +0000
Hi Axel,
Thanks for you suggestions.. I got a response from Greg Guerin on the java-dev list who pointed out that:
tell application "iTunes" add "Macintosh HD:Users:zuhayrkhan:Music:Test.mp3" end tell
... actually does exactly what I wanted to do - I'd read the comment for this "add one or more files to a playlist" to mean that this was only going to add to a playlist, but sure enough - it adds the file but doesn't start playing it.
Axel Luttgens wrote: 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.
Anyway - I suspect you're right about "delay" being the root of the problem I was seeing in the interoperability between java and AppleScript.
I'm not too keen on the idea of invoking a shell/php command to introduce the delay - my using a delay of 0.1 was in an effort to stop the unwanted playing as soon as possible - but even then; it would have caused a bit of a nasty busy loop.
Given what you suggest about the "special" nature of delay - I think if I was going to have to tackle this problem in some other context, I'd be inclined to either bring the delay element into Java and invoke a "stop if player state is playing" AppleScript at regular intervals.
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
I appreciate the code was a little ugly with all the debug, but with the exception of a test I'd added to check player state were stopped before going into the "wait until state is playing" repeat - that's exactly what my code was doing or even:
open "somefile" wait for some suitable fixed delay stop
The problem with this is that I would never (with any certainty) know how long to wait as files I am going to be importing will be of various different sizes.
Anyway, thanks for your post - much appreciated.
Best,
Zuhayr |
_______________________________________________
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