Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NeeLonMac

macrumors newbie
Original poster
Oct 6, 2010
16
0
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

macrumors newbie
Original poster
Oct 6, 2010
16
0
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

macrumors member
Aug 25, 2008
31
0
NE Florida
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:

PHP:
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

macrumors newbie
Original poster
Oct 6, 2010
16
0
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.

Code:
-- 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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.