Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 30, 2010, 06: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, 07: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, 09: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 10:05 PM.
andmr is offline   0 Reply With Quote
Old Oct 31, 2010, 04: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

Similar Threads
thread Thread Starter Forum Replies Last Post
Screen copy active window Barney63 MacBook Pro 3 Mar 14, 2014 01:49 AM
AppleScript to playpause active media Vegerot Mac Applications and Mac App Store 0 May 26, 2013 11:54 AM
Show Window without activating (keep application below it active) wesleyh Mac Programming 0 Feb 26, 2013 05:08 AM
Is there a more active AppleScript forum site? moonman239 Mac Programming 7 Jan 22, 2013 06:56 PM
Active Window in Mac OSX saqibjaan Mac Programming 11 Sep 14, 2012 08:12 AM

Forum Jump

All times are GMT -5. The time now is 04:36 PM.

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

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