Applescript to run at shut down

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

  1. Monaj macrumors regular

    Joined:
    May 24, 2009
    #1
    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:
    HTML:
    http://discussions.apple.com/thread.jspa?threadID=1375949&tstart=0&messageID=7088687#7088687
    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:

    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
    else
        tell application "Safari"
            open location "www.gmail.com"
        end tell
    end if
    continue quit
    end quit
    but it is not working for me!

    Can anyone suggest where I may be wrong ??

    thanks,

    Monaj
     
  2. mysterytramp macrumors 65816

    mysterytramp

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

    mt
     
  3. Monaj thread starter macrumors regular

    Joined:
    May 24, 2009
    #3
    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

    Joined:
    Aug 9, 2009
    #4
    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:

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

    Joined:
    May 24, 2009
    #5
    Thanks, chown.... it worked :)
     

Share This Page