Terminating AppleScript with "Cancel" Input

Discussion in 'Mac Programming' started by PowerBook-G5, May 14, 2015.

  1. PowerBook-G5 macrumors 65816

    PowerBook-G5

    Joined:
    Jul 30, 2013
    Location:
    The United States of America
    #1
    I'm working on an AppleScript that allows me to create new reminders with a simple keystroke. I have it so that I can select the list to add it to, create a name, and then add a note to the reminder. For each window, there are two buttons: a cancel button, and a button that advances to the next step. The second button works just fine, but it's the cancel button that I can't figure out.

    If I click on the Cancel button in the first window, it only advances to the next window, making me click the other Cancel button to quit running the script. I'd like to make the first Cancel button, when clicked, terminate the script. Any help would be appreciated!

    Here's the code:
    Code:
    tell application "Reminders"
    	
    	(choose from list {"Personal", "Daily", "School", "AppleScript Tests"} with title ¬
    		"Choose a list" with prompt "Choose a list in which to create a new reminder." OK button name "Select" cancel button name "Cancel" default items {"AppleScript Tests"})
    	
    	set mLA to result as text
    	
    	set mL to mLA
    	
    	set mN to the text returned of (display dialog "Enter a new reminder." default answer "" buttons {"Cancel", "Next"} with title "New Reminder" default button "Next")
    	
    	set mN to the text returned of (display dialog "Enter a note for the reminder." default answer "" buttons {"Cancel", "Create"} with title "New Reminder" default button "Create")
    	
    	tell application "Reminders"
    		set mR to make new reminder in list mL
    		set name of mR to mN
    		set body of mR to mN
    		
    	end tell
    	
    end tell
     
  2. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    The "cancel" button in choose from list does not generate an error like other dialogs, instead it returns false, so you just need to test for that.
     

Share This Page