Jump to content

Quitting Retrospect from script


Recommended Posts

I'm trying to have Retrospect shut down automatically from APC's PowerChute. I'm running Retrospect 6.1.126 with Driver update 6.1.7.101 installed on MacOS 10.4.7 and usually have Retrospect running as a backup server. Even after following the directions in KB article 6438, I'm still getting the "Really Quit?" dialog each time I quit (the one with "Start Server", "Don't Quit", and "Quit" buttons). I've gone so far as to try to drive the Quit button via the System Events application from AppleScript, but the Quit button isn't taking the click event.

 

Any clues?

 

The AppleScript I'm using is below. It will resolve the "Quit" button in the "Really Quit?" dialog, but the click doensn't seem to take -- even when the code is pulled out to a test script when the dialog is open.

 

Code:



tell application "System Events"

set retroRunning to ("Retrospect" is in (name of every process))

end tell

 

if retroRunning then

tell application "Retrospect"

activate

stop Backup Server

stop execution

end tell

tell application "System Events"

tell process "Retrospect"

tell menu bar 1

tell menu bar item "Retrospect"

tell menu 1

click menu item "Quit Retrospect"

end tell

end tell

end tell

end tell

repeat

set retroRunning to ("Retrospect" is in (name of every process))

if (not retroRunning) then

exit repeat

end if

try

tell process "Retrospect"

set quitDialogOpen to ("Quit" is in (name of every button of window 1))

if (quitDialogOpen) then

click button "Quit" of window 1

exit repeat

end if

end tell

end try

end repeat

end tell

end if


Link to comment
Share on other sites

hi again,

 

sorry, i posted the link before testing. it did not work for me. however, this did:

 

Code:



tell application "Retrospect"

stop execution

stop Backup Server

ignoring application responses

quit

end ignoring

end tell

 

-- wait a second

delay 1

 

-- press Return

-- (Return is interpreted as a click of the default button, "Quit", in the "Are you sure" dialog box)

tell application "Retrospect" to activate

tell application "System Events" to tell process "Retrospect" to keystroke return


 

seems you need to 'activate' Retrospect before sending the return. hope that helps.

Link to comment
Share on other sites

Thanks for the pointer. Weird that things were quiet for a while and then came up again.

 

Here's my final script:

 

Code:



-- Quit Retrospect if it is running

-- Retrospect likes to pose a "Really Quit?" dialog before closing.

-- If it shows the dialog, select the default button by sending a return key via SystemEvents

-- (Quit is the default button).

-- Sending a click to the "Quit" button via SystemEvents didn't work.

tell application "System Events"

set retroRunning to ("Retrospect" is in (name of every process))

end tell

if retroRunning then

tell application "Retrospect"

activate -- Activation worked better here than just before sending the keystroke below.

stop execution -- The stop commands should be in this order

stop Backup Server -- Flipping the order caused the server to restart

ignoring application responses -- Don't block on the command

quit

end ignoring

end tell

tell application "System Events"

repeat

set retroRunning to ("Retrospect" is in (name of every process))

if (not retroRunning) then

-- If Retrospect quit without posing the confirmation dialog, rejoice

exit repeat

end if

try

tell process "Retrospect"

-- It may take a few seconds for the "Really Quit?" dialog to open

-- Wait for it...

set quitDialogOpen to ("Quit" is in (name of every button of window 1))

if (quitDialogOpen) then

keystroke return

exit repeat

end if

end tell

end try

end repeat

end tell

end if


 

It's mainly the code above but should be a little more robust. It'll work if Retro's not running, if Retro stops showing the "Really Quit?" dialog in the future, or if it takes a couple of seconds for things to settle down before the Quit dialog is shown.

 

As I don't pretend to be an AppleScript expert, any suggestions are appreciated.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...