Using ScriptSync I’ve almost got a working solution. Here were the various complications I faced:
1.) The sound settings can only be changed BEFORE Apple Video Player (AVP) launches and AFTER it has quit
2.) The remote control, which should have the ability to launch the AVP OR if already running and not frontmost, bring to front OR if frontmost, quit it. But if I want the script to run instead before the AVP, I have to replace the AVP with the script – meaning that pressing the remote button brings THE SCRIPT frontmost or quits it.
3.) In order for the other remote control functions to work, this script must stay open as long as AVP is running.
4.) AVP’s dictionary has no “quit” command, so as far as I know, there is no way to make it quit via an AppleScript. (I tried, and the script would crash on each quit attempt.)
5.) I’d like this to be idiot proof, so any order of launching and quitting components, not just the prefered order, gets the desired response.
My solution: three scripts, two of which are tied to ScriptSync.
The first, “Launcher” changes the settings as necessary, launches a second script, called “Shell,” and then begins an idle loop. From here on, Launcher is merely mimicing the remote – if Launcher is brought to front, it brings the AVP to front, unless AVP was the last front application, in which case Launcher tells Shell to quit before itself quitting. Obviously, a stay open script.
Shell consists entirely of an idle loop which checks if it is frontmost. If it is and AVP is still running, AVP is set to frontmost. Again, this is a stay open script.
Shell has a “tied to launch” alias to the AVP in the ScriptSync folder. Therefore, when Shell launches, the AVP launches, when Shell quits, the AVP quits. (This gets around problem 4 from above.)
The AVP has a “tied to quit” script in the ScriptSync folder. This script, called “QuitScript” first restores the sound settings to the previous one, then checks the other scripts. If Launcher or Shell are still running, they are quit.
So far, so good, if a bit awkward. Launcher stays open and handles the remote, settings are guaranteed to be changed only before and after AVP’s run, and the scripts can quit AVP by quitting the otherwise useless Shell script. You can start from either Launcher or Shell and get the proper settings and TV performance. The one problem is if the user runs Launcher first, the Shell idle script doesn’t seem to run – you can bring Shell to the front and it just stays there.
Is it impossible to have two separate scripts running idle handlers concurrently? Is there an easy way to approximate this?
Is there any way to run scripts invisibly (not in the Application Switcher) yet still have frontmost values?
Kel – what is “scripting locations” and how do I go about doing it?
Can anyone think of a cleaner solution to my 5 problems?
Thanks for all your help guys!