🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #17189

Re: Folder actions and InDesign scripts

#17189
From: Dave Saunders
Date: Mon, 30 Jun 2003 15:17
30 lines
2353 bytes
Here's an example of an idle handler that I use in a script I wrote to monitor iTunes. You save the whole script as stay open application and make the main script an on run handler:

on run
 -- blah blah blah
 return
end run

Then, when you first fire it up it runs that handler. When it finishes, idle messages are sent to the idle handler. If you want to influence how often the handler runs (the default is once a second, I believe), return an integer from either the idle handler or the run handler and the integer determines how many seconds before the next idle message is sent.

on idle
 tell application "iTunes"
  try
   if player state is not stopped then return 5
  on error
   return 5
 end try
 end tell
 pickOne()
 return 30
end idle

So, if iTunes is busy, my script comes back 5 seconds later (note that in some states, iTunes might cause an error when I try to get the player state; if that happens, the script shrugs its shoulders and tries again five seconds later).

If iTunes is not playing anything, then the pickOne handler selects a piece to play and forces me to listen to it for a minimum of 30 seconds.

I use this script to randomly play classical works. The built-in random features in iTunes make this less necessary than when I first created it, but actually I've grown to appreciate the 10 seconds or so that pickOne takes to set up the next piece; iTunes' random feature doesn't include any kind of delay. Having a Vivaldi concerto startup while the last notes of a Shostakovich symphony are still rattling around my mind is a bit disconcerting.

Hope this helps.

Dave
Technical Details
Message-ID: <1de9b5e6.3@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.media.kyoto-u.ac.jp!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de9b5e6.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,509f53da23030a35
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-06-30 08:38:30 PST
From: "Dave Saunders" <daves@pdsassoc.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.media.kyoto-u.ac.jp!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Folder actions and InDesign scripts
Message-ID: <1de9b5e6.3@WebX.la2eafNXanI>
Date: Mon, 30 Jun 2003 08:17:07 -0700
References: <1de9b5e6.-1@WebX.la2eafNXanI>
Lines: 46
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit