PDA

View Full Version : Applescript - Button returned error




bgrantmyre
Jul 30, 2013, 05:24 PM
I'm trying to make code which allows me to open my favourite websites with the click of a button, and with all my passwords saved on my mac log in at the same time, i keep experiencing a problem i cant fix when i try to run this all it says is "Can't get button returned of {{button returned:"Facebook"}}." I'm very new to this so can someone help me fix this problem?

tell application "Finder"
set x to {display dialog "Which site would you like to visit?" buttons {"Facebook", "Twitter", "Gmail"} default button 1}
if button returned of the result is "Facebook" then
tell application "Safari"
activate
open location "http://facebook.com/"
tell application "System Events"
activate
keystroke return
end tell
end tell
end if
end tell



Red Menace
Jul 30, 2013, 07:04 PM
The display dialog command returns a record that contains the name of the button, and can also include returned text and an indication that the dialog gave up, if applicable. By using braces around the command in your assignment statement, you are creating a single item list containing the dialog results - the error is that there is no longer a button returned property, since the record is now just an item in the list.

Since your example script is not using the variable that you assigned the dialog results to, you can just use the statement:

display dialog "Which site would you like to visit?" buttons {"Facebook", "Twitter", "Gmail"} default button 1

Also note that you don't need Safari for the open location command - that command is from the StandardAdditions scripting addition.