Quote: Originally Posted by
Count_Fred 
BugByte: Can you say more about how the idle loop is unstable? I'm about to start using it to pull values off an Arduino (microcontroller board) and haven't had any problems with the code on my test machine so far.
Well, it becomes a problem when you have a full featured app programmed. What sealed it for us was that when you clicked a button on the screen, it would light up to show clicked, but it would never un-click. Until you pressed it a SECOND time.
The way we had it set up, the idle handler was what got called whenever you pressed a button and then routed the action off to the proper script depending on what screen was displayed. This allowed us to reuse buttons from screen to screen and so forth.
In any case, the idle handler makes it difficult to debug the script because it fires whenever it has time -sometimes in the middle of one of your other scripts running. So the debugger will be following through some code you're trying to debug and then shoots you off to the idle handler over and over. Makes it difficult to debug.
As for the sleep/wake problem, we did solve that pretty easily. You have to program the script as an application. That allows you to read and write preferences. Once you can do that, you can set those prefs according to what's going on with the various apps on the screen or inputs from the keyboard.
We had the same issue of not being able to pause iTunes. You get around it by setting a preference when you click a button onscreen or get some keyboard input. Your application 'sets' that preference to pause, then pauses iTunes. Next time through, you compare the application's pause pref with the iTunes state. If they are BOTH pause, then you stay paused.
Then, when you click the button or hit the key, you set the app's pref to 'play' and next time through, the idle handler compares that to the iTunes state, which is paused. It starts iTunes playing at that point.
I don't think you can read/write pref files through the script editor, although I could be wrong. You have to use XCode to build an applescript application.