1

I'm creating a cool script to bother me by asking to close some distracting apps that I open without realising. For that, I do this:

MINUTES_UNTIL_ASK_TO_CLOSE=`osascript -e 'set T to text returned of (display dialog "Do you really want to use this app?" default answer "1" with icon caution buttons {"Close to better Focus or Relax", "Remember again after minutes..."} default button "Remember again after minutes...")'` 

It gets the text entered in the input (the number of minutes till remember again to close). The problem is that I'm not being able to find how to get the button that has been pressed.

I found the following beautiful code in another answer in this platform:

set theResultReturned to (display dialog "hallo" buttons {"h", "a"} default button "a" default answer "") set theTextReturned to the text returned of theResultReturned set theButtonReturned to the button returned of theResultReturned 

But I'm failing to get the variable to know which button has been pressed:

BUTTON_PRESSED=`osascript -e '... ?? 
1
  • osascript returns the text representation of the result of the script, so you will need to have whatever you are doing split that string into the desired components. Commented Apr 5, 2023 at 18:34

1 Answer 1

1

You may want to try something like this first command in Terminal:

DIALOG_RESULTS="$(osascript -e 'set {T,B} to {text returned, button returned} of (display dialog "Do you really want to use this app?" default answer "1" with icon caution buttons {"Close to better Focus or Relax", "Remember again after minutes..."} default button 2)' -e 'return T & "\t" & B')" &&MINUTES_UNTIL_ASK_TO_CLOSE="$(echo "$DIALOG_RESULTS" |cut -f 1)" &&BUTTON_RETURNED="$(echo "$DIALOG_RESULTS" |cut -f 2)" 

Running that code will create 3 new variables

  1. $DIALOG_RESULTS
  2. $MINUTES_UNTIL_ASK_TO_CLOSE
  3. $BUTTON_RETURNED

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.