display dialog "New Entry"default answer "" buttons {"Cancel", "Add"} default button 2
copy the result as list to {text_returned, button_pressed}
if button_pressed is equal to "Cancel" then
error -128
else
set csv_data to text_returned
-- more code
end if
The code works fine in ScriptEditor. Now I try to use it in a Service and something strange happens.
The button gets recognized properly, since its doing the loop correct.
BUT
Whatever I enter in the textfield csv_data will be “Add” (the button text !??)
Why is it doing this in the evice when it is working fine in Scripteditor? What am I missing?
You’re coercing a record to an list, which results in an list with an unknown order. Best way to do it is like getting the values by their keys and not by it’s index.
set dialogResult to display dialog "New Entry" default answer "" buttons {"Cancel", "Add"} default button 2
tell dialogResult to set {button_pressed, text_returned} to {button returned, text returned}
if button_pressed is equal to "Cancel" then
error -128
else
set csv_data to text_returned
-- more code
end if