Script editor app shutdown alert

Discussion in 'Mac Programming' started by Barden95, Oct 25, 2018.

  1. Barden95 macrumors newbie

    Joined:
    Oct 25, 2018
    #1
    Hi All,

    I'm trying to make an app that will display a prompt upon shutdown asking if the user has logged their hours via our online system 'timely'. The idea is that the reminder appears 'Have you logged your timely hours?' with the options 'yes' or 'no'. 'Yes' allowing the machine to shut down and 'No' opening Google Chrome on the Timely website.

    So far using the following script the alert is popping up, but when I select 'No' the machine is still shutting down. Can anyone help?

    say "Aye up! I'll be reminding you to log your hours on timely when you shut down. "

    on quit


    set the alert_message to "Have you logged your hours on Timely?"

    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 "Google Chrome"

    open location "app.timelyapp.com"

    end tell

    end if

    continue quit

    end quit
     
  2. Red Menace macrumors 6502

    Red Menace

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    The continue quit statement is what is, well, continuing the quit. If you move that to your "Yes" block the application won't quit.
     
  3. Barden95 thread starter macrumors newbie

    Joined:
    Oct 25, 2018
    #3
    Thanks so much for the answer! But, as is probably obvious i'm a complete stranger to this stuff, where should I move it to?
     
  4. Red Menace macrumors 6502

    Red Menace

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #4
    Not sure about the race between shutting down and quitting, but it would be something like:

    Code:
    on quit
        set the alert_message to "Have you logged your hours on Timely?"
        display dialog the alert_message buttons {"Yes", "No"} default button 1
        set my_choice to the button returned of the result
        if my_choice is "Yes" then
            tell application "Finder" to shut down
            continue quit
        else
            tell application "Google Chrome"
                open location "app.timelyapp.com"
            end tell
        end if
    end quit
    See the (legacy) AppleScript Language Guide.
     
  5. Barden95 thread starter macrumors newbie

    Joined:
    Oct 25, 2018
    #5
    Amazing, this has worked perfectly. Thanks so much!
     

Share This Page

4 October 25, 2018