Support
All support resources for our products. Here you can find answers to frequently asked questions, discuss with other users, recover a lost license code or file a support request.
Forum closed
This forum was closed and turned into an archive effective April 21, 2018. It is no longer possible to create new topics or reply to existing topics.

Thanks everyone for all the great questions and contributions over the years.

Please use the Contact form to get in touch.

Remote Buddy Forum

Overview 

AuthorThread
User

01.03.2011 04:07:54
Re: Script to exit FrontRow

This posting is older than 6 months and can contain outdated information.
 
I seem to get an occasional issue where RemoteBuddy hangs - I think perhaps due to FrontRow interaction. In this situation the remote becomes unresponsive and the mouse beachballs over the RB menu icon; I have to resolve by force-quitting RB. So I was wondering if there's a recommended way to close FrontRow from a script.

 
When Remote Buddy executes an AppleScript it (RB) remains unable to process anything else until the script has finished execution. So, if something goes wrong in a script, Remote Buddy will appear to hang until the script reaches its timeout value (the default is 120 seconds). Remote Buddy may also appear to hang with complex scripts where it remains unusable until the script completes. You can get around this by setting the timeout period to a lower value:

-- Begin Code -- 
tell application "My App" 
with timeout of 20 seconds 
--do something 
end timeout 
end tell 
-- End Code --

or by handing execution to the shell:

-- Begin Code -- 
do shell script "osascript the/path/to/your/script" 
-- End Code --

In the above example all you're doing is telling the UNIX part of OS X to run a script, so, the only part Remote Buddy cares about is "do shell script". Once that's executed—which, as a rule, should be instantaneous—Remote Buddy will be responsive, no matter how long your timeout or the complexity of your script.

Currently I have (for closing all existing apps):

to closeAllApps(theAppName) 
-- snip -- 
end closeEyeTV

 
You're off to a good start but, if I may offer some help here, your code can be much more efficient. It may seem like there's no point to saving half or one-tenth of a second when everything runs so quickly anyway, but these times add up, not to mention that the more text you've written, the longer it takes *you* to read and/or follow the logic. You'd be amazed at how much troubleshooting time one can save if short, efficient code is used from the start. And, as a general rule, GUI scripting is the absolute *last* method you should use.

EyeTV doesn't need to be "special"; there is a background process (EyeTV Helper) that controls your scheduled recordings and will launch the main app if necessary. That being said, I like to leave EyeTV running on my HTPC. All of your EyeTV code can be replaced with:

-- Begin Code -- 
tell application "EyeTV" to close every window 
-- End Code --

Your Front Row code can be simplified to:

-- Begin Code -- 
try 
do shell script "killall 'Front Row'" 
end try 
-- End Code --

And, overall, the entire block can be reduced as such:

-- Begin Code -- 
to closeAllApps(theAppName) 
set appNameList to {"iTunes", "Plex", "DVD Player"}

-- Kill Front Row 
if theAppName is not "Front Row" then 
try 
do shell script "killall 'Front Row'" 
end try 
end if

-- Close all EyeTV windows (or quit if desired) 
if theAppName is not "EyeTV" then 
tell application "EyeTV" to close every window 
end if

-- Code to quit iTunes, Plex, and DVD Player 
repeat with currentAppName in appNameList 
if currentAppName is not equal to theAppName then 
tell application currentAppName to quit 
end if 
end repeat 
end closeAllApps 
-- End Code --

Last edited: 01.03.2011 04:09:05

Last edited: 01.03.2011 04:12:41 

Thread-display::