Applescript to run at shut down

Discussion in 'Mac Programming' started by Monaj, Jan 21, 2010.

  1. Monaj macrumors regular

    May 24, 2009
    Hi all,

    I am trying to make an application using AppleScript which can remind to check my mails, if I forget to check, at shutdown.

    I took help from this link:
    In this link they have suggested that I can run a quite application which can be started at login and when I will try to shut down, system will try to close it and desired result will be obtained!

    I have tried this script code:

    say "Good morning Miraaj! I will be reminding you to check your mails at shutdown. Have a rocking day!!"
    on quit
    set the alert_message to "Have you checked your mails?"
    display dialog the alert_message buttons {"Yes", "No"} default button 1
    set the my_choice to the button returned of the result
    if my_choice is "Yes" then
        tell application "Finder"
            shut down
        end tell
        tell application "Safari"
            open location ""
        end tell
    end if
    continue quit
    end quit
    but it is not working for me!

    Can anyone suggest where I may be wrong ??


  2. mysterytramp macrumors 65816


    Jul 17, 2008
    What's not working? Is the script running? Is it a stay-open script? Where is it saved? Have you saved it to StartupItems?

  3. Monaj thread starter macrumors regular

    May 24, 2009
    It is displaying alert message at launch whereas I want it to show it only during shutdown when system tries to quit it!
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    You probably haven't saved it as a Stay Open application. It's one of the Options checkboxes.

    When the script isn't saved as Stay Open, then it quits after the initial say command finished. That means it runs its Quit handler, which shows the dialog.

    This problem has nothing to do with the script itself. The problem lies entirely in how the application is saved. For example, this much simpler script:

    say "Hello."
    on quit
    	say "Goodbye"
    	continue quit
    end quit
    When saved as Application with Stay Open checked, it stays open after saying hello. When I choose Quit from its Dock menu, it says goodbye and quits.

    When saved as Application without Stay Open checked, it says hello, then says goodbye and quits. It does not stay open.
  5. Monaj thread starter macrumors regular

    May 24, 2009
    Thanks, chown.... it worked :)

Share This Page