Tuesday, August 20, 2019

#1 2003-11-21 12:13:35 pm

remote
Member
From:: Baltimore Maryland
Registered: 2003-03-23
Posts: 1

Can I not have 2 loops running simultaneously in applescript

Hello all, I am at a point where I need some ideas. I'm writing some scripts
that work with QuickTime Player and Speech Recognition Server in OS X. In a
nutshell, the script listens for a series of words that correspond to chapters
in my movie. And when it hears one, it tells the movie to jump to that
chapter...so it's a voice activated video navigation thing. I have all of the
above working no problem but there is a feature that I'm having a hard time
getting to work...what the function is supposed to do is monitor the playback
of the movie and when it gets to end of the currently playing chapter, jump
back to the chapter that was playing before the current chapter was playing.
So the events would break down like this:

--Applet 1
1. Play Movie
2. Listen for command
3. Tell movie to jump from the currently playing chapter to the spoken chapter
heard in step 2 and then call step 4 in applet 2

--Applet 2
4. Loop, waiting until the end of the chapter that was jumped to and then
return to the chapter that was jumped from.

It seemed logical that steps 1-3 should be in one applet and step 4 in another
because I need them to both run at the same time.

Seems relatively easy...but the problem seems to be this. The Speech
Recognition Server's Listen command is a loop...and it continues to loop until
it hears something (or until it times out, but I'm not setting that property
because it needs to listen continuously). So because the script is tied up
with the loop in step 2, when I call the loop in step 4, in my other applet,
it doesn't get to run more than once...it appears to be returning control to
the calling applet immediately. I've tried "ignoring application responses"
when calling the playback monitoring, loop function in my other applet but it
has no effect...

So the real question is:

Does this mean that I cannot have 2 loops running simultaneously in
applescript...  :?:

Is there some fundamental characteristic of applescript that I'm missing?

Thanks

Offline

 

#2 2019-08-09 05:50:05 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 425

Re: Can I not have 2 loops running simultaneously in applescript

I think, you can't have 2 separate loops running simultaneously in 1 Apple-script. But you can run 1st loop nested in 2nd loop,  and this way you should build your code to get what you want. Or, you should make 2 separate stay-open applets and run them together.

Other way is implement GO TO statement's logic, but this will be lumpish solution for one AppleScript which has not GO TO command (and no need as I think).

TEST. Test as 1 applet too:

Applescript:


repeat 5 times
   say "one"
   set myCount to true
   repeat while myCount is true
       say "two"
       set myCount to false
   end repeat
end repeat

Last edited by KniazidisR (2019-08-09 06:44:45 pm)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

#3 2019-08-10 11:45:44 am

vince
Member
Registered: 2002-12-14
Posts: 63

Re: Can I not have 2 loops running simultaneously in applescript

Things to read about and test:

1) Put your loops in separate script objects?

2) You can run some things in parallel in Applescript, apparently:  https://macscripter.net/viewtopic.php?id=24573


vince angeloni

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)