Applescript - bring popup window to front?

Discussion in 'Mac Programming' started by poobear, Apr 21, 2011.

  1. macrumors 6502a

    poobear

    Joined:
    Nov 20, 2009
    #1
    Hi!

    I have this applescript:

    Code:
    repeat
    	display dialog "Take a break!" buttons {"Ok"} default button 1
    	delay 600
    end repeat
    I have saved this as minibreak.app file and have it running reminding me to take short breaks. Problem is, these popup windows happens in the background, I just hear the popup sound and see the dock icon jumping. I would like to bring these windows to the front so I never miss them.

    I googled and tried to add
    Code:
    set window 1 of application "minibreak" to frontmost
    but that did not work.

    Does anyone have an idea on how to solve this?

    Thanks!
     
  2. macrumors member

    Joined:
    Dec 28, 2010
    Location:
    Scotland
    #2
    Just activate it to bring your script to the front.

    Code:
    repeat
    	activate
    	display dialog "Take a break!" buttons {"Ok"} default button 1
    	delay 600
    end repeat
    
     
  3. thread starter macrumors 6502a

    poobear

    Joined:
    Nov 20, 2009
    #3
    Thanks! That was an easy fix.

    Also, I can't quit this program either by right clicking on the Dock icon or by clicking Close in the Apple menu. Does anyone know why this is? I have to force quit it every time.
     
  4. macrumors 65816

    mysterytramp

    Joined:
    Jul 17, 2008
    Location:
    Maryland
    #4
    You can't quit because of this:

    Code:
    display dialog "Take a break!" buttons {"Ok"} default button 1
    Or more precisely "buttons {"Ok"} default button 1"

    Ordinarily, display dialog would present two buttons, OK and Cancel. With Cancel, you'd be able to exit the script gracefully. But by adding "buttons {"Ok"} default button 1" you've told AS you don't want the standard.

    Change that one line to:

    Code:
    display dialog "Take a break!"
    If you press "OK," the script proceeds normally and delays 600 seconds. Hit cancel and it exits.

    mt
     

Share This Page