PDA

View Full Version : Applescript active window problem




NeeLonMac
Oct 30, 2010, 05:51 AM
Hey guys, I created a script that will put the computer to sleep when I open it with voice commands. But because I don't want it to go to sleep by accident, I installed a "Are you sure?" dialog box.
Of course, I want to handle that dialog box with my voice as well, because the whole idea is putting my computer to sleep with my voice.

Problem is, I can't get the new dialog window active. I have to click the dialog window, before it accepts my "Yes" or "No". The rest all works fine.

How can I fix this?



NeeLonMac
Oct 30, 2010, 06:18 AM
I'm also creating a script that will open this site, on the specific tread when somebody replied on a tread of mine, so don't be shy and reply! :)

andmr
Oct 30, 2010, 08:07 PM
Problem is, I can't get the new dialog window active. I have to click the dialog window, before it accepts my "Yes" or "No".
How can I fix this?

You might try adding tell me to activate immediately preceding the display dialog command ("me" being the running script itself).

For example:

tell application "Finder" to activate
tell me to activate
display dialog "Blah"


Notice what would happen if tell me to activate is commented out or removed; adding it ensures that the dialog window comes to the fore, since the Finder is no longer the frontmost application.

NeeLonMac
Oct 31, 2010, 03:36 AM
Great, it works! Thanks!

Since I love it when I can find complete working scripts when I am in search of one, I'll post the working script here.

-- tell application "Finder" to activate
tell me to activate
set question to display dialog "Are you sure you want the computer to go to sleep?" buttons {"Yes", "No"} default button 1 with icon 1
set answer to button returned of question
if answer is equal to "Yes" then
say "Going to sleep now"
tell application "Finder"
sleep
end tell
end if