Can I have a dialog that doesn't close when a button is clicked?

Can i have a dialog with 2 buttons that doesn’t close when one of them is clicked?


		display dialog display_text buttons {"Close", "Stop"} default button 1

		set the button_pressed to the button returned of the result
		
		if the button_pressed is "Close" then
			close doc_ref
		else if the button_pressed is "Stop" then
			stop doc_ref
		end if

I want the STOP button to stop playback of the app (QuickTime) but for the dialog to stay open.

TIA,
Jim

Hi, Jim.

You can’t stop the dialog from closing, but you can make it come back again.

repeat -- until the 'exit repeat' when the "Close" button is pressed
  display dialog display_text buttons {"Close", "Stop"} default button 1
  
  set the button_pressed to the button returned of the result
  
  if the button_pressed is "Close" then
    close doc_ref
    exit repeat
  else if the button_pressed is "Stop" then
    stop doc_ref
  end if
end repeat

I know this is for your QuickTime script and that QuickTime Player is displaying the dialog. The drawback is that while the dialog’s open, you can’t do anything with the player itself. What you can do is to get the script itself to display the dialog instead. It’ll then be the script holding the dialog open and you can easily switch to QuickTime Player and use its controls.

-- Assuming this is in a 'tell application "QuickTime Player"' block

tell me to activate

repeat -- until the 'exit repeat' when the "Close" button is pressed
  tell me
    display dialog display_text buttons {"Close", "Stop"} default button 1
  end tell
  
  set the button_pressed to the button returned of the result
  
  if the button_pressed is "Close" then
    close doc_ref
    exit repeat
  else if the button_pressed is "Stop" then
    stop doc_ref
  end if
end repeat

Not only smart, but a mindreader :slight_smile:

That works perfectly! . . . well in terms of operation the repeat dialog closing and persistently opening again when "Stop"is pressed is a little inelegant. Is that an AS limitation in this case?

Jim

Well, it no doubt feels like a limitation when you want something different. :slight_smile: The dialog’s actually meant to get out of the way once the user’s clicked a button. It’s quite a marvellous system when you think what ‘display dialog’ actually does in return for a minimum of scripting effort.