PDA

View Full Version : Applescript Studio Error




Roadrun3r
May 30, 2011, 10:58 AM
This is my first time using applescript studio, so I decided to make a real simple application to get used to it. Its weird. Because I knew how to do next to nothing in Studio, I grabbed a quick button tutorial (http://macscripter.net/viewtopic.php?id=24751), which as you can see, makes up most of the script for my app. But I didn't necessarily like what the tutorial made, so I modified the script to suit my purposes.
My goal is to make an application where you choose a voice, type in some words, and the computer will talk to you (Rather than going to settings every time).
Yet I keep getting the same error. (The "Take me to your leader" part is what I typed in.)

on clicked theObject
if title of theObject = "Quit" then
quit
else if title of theObject = "Process" then
display dialog "Say.." default answer "" buttons {"Say it!", "Go back"}
set wordstosay to text returned of result
if button returned of result = "Say it!" then say wordstosay using voice
end if
end clicked

on choose menu item theObject
set voice to the title of current menu item of theObject
end choose menu item

on launched theObject
tell window 1
set title of button "button1" to "Quit"
set title of button "button2" to "Process"

set thePopupItems to {"Alex", "Agnes", "Bad News", "Bells", "Cellos", "Good News", "Pipe Organ", "Whisper", "Zarvox"}
tell menu of popup button 1
delete every menu item
repeat with aMenuItem in thePopupItems
make new menu item at end of menu items with properties {title:aMenuItem}
end repeat
end tell
end tell
end launched



Roadrun3r
May 30, 2011, 01:09 PM
Here's the actual project for anyone who is curious and has time on their hands.

Roadrun3r
Jun 2, 2011, 03:56 PM
Is there any way I can fix this??? ^^^

Red Menace
Jun 2, 2011, 07:42 PM
result is a global property that contains the results (if any) of the last statement - your problem is a basic AppleScript issue, and not necessarily specific to AppleScript Studio.

The long version of your error alert is 'Can't get button returned of "Take me to your leader"', which is a pretty good clue. In your example, you are setting a variable to the text returned of the dialog, so the result property is set to that value - the string "Take me to your leader". Later in your script you are trying to get the button returned of that result, which fails because it is now just a string and doesn't have that property.

You need to be careful when using the result property. Since it can be changed by just about anything, all it takes is a few edits for it to contain something unexpected. The fix is to not use the result property in this way - for example, you can store the original dialog results in a variable and refer to that instead:

set myResult to (display dialog "Say.." default answer "" buttons {"Say it!", "Go back"})
set wordstosay to text returned of myResult
if button returned of myResult = "Say it!" then say wordstosay using voice