Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 30, 2010, 05:51 AM   #1
NeeLonMac
macrumors newbie
 
Join Date: Oct 2010
Applescript active window problem

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 is offline   0 Reply With Quote
Old Oct 30, 2010, 06:18 AM   #2
NeeLonMac
Thread Starter
macrumors newbie
 
Join Date: Oct 2010
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!
NeeLonMac is offline   0 Reply With Quote
Old Oct 30, 2010, 08:07 PM   #3
andmr
macrumors member
 
Join Date: Aug 2008
Location: NE Florida
Quote:
Originally Posted by NeeLonMac View Post
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 Code:
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.

Last edited by andmr; Oct 30, 2010 at 09:05 PM.
andmr is offline   0 Reply With Quote
Old Oct 31, 2010, 03:36 AM   #4
NeeLonMac
Thread Starter
macrumors newbie
 
Join Date: Oct 2010
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
NeeLonMac is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Applescript activation switch? wrignj08 Mac Programming 5 Jun 21, 2011 10:19 AM
AppleScript to mount Windows shares dwright1974 Mac Programming 3 May 1, 2011 05:36 PM
iTunes Resize Error AppleScript Konki Mac Applications and Mac App Store 1 Nov 21, 2010 12:47 PM
Applescript to make Desktop become active window xharkila Mac Programming 5 Mar 11, 2010 11:20 PM
Active Windows Problem OS X Parental OS X 5 Nov 30, 2008 05:40 AM


All times are GMT -5. The time now is 08:59 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC