Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 30, 2011, 10:58 AM   #1
Roadrun3r
macrumors newbie
 
Join Date: May 2011
Applescript Studio Error

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.)

Code:
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
Attached Thumbnails
Click image for larger version

Name:	Error.jpg
Views:	9
Size:	41.5 KB
ID:	287387  
Roadrun3r is offline   0 Reply With Quote
Old May 30, 2011, 01:09 PM   #2
Roadrun3r
Thread Starter
macrumors newbie
 
Join Date: May 2011
The file.

Here's the actual project for anyone who is curious and has time on their hands.
Attached Files
File Type: zip Button Demo.zip (72.5 KB, 4 views)
Roadrun3r is offline   0 Reply With Quote
Old Jun 2, 2011, 03:56 PM   #3
Roadrun3r
Thread Starter
macrumors newbie
 
Join Date: May 2011
Last try.

Is there any way I can fix this??? ^^^
Roadrun3r is offline   0 Reply With Quote
Old Jun 2, 2011, 07:42 PM   #4
Red Menace
macrumors regular
 
Join Date: May 2011
Location: Littleton, Colorado, USA
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:

Code:
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
Red Menace is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Applescript - Button returned error bgrantmyre Mac Programming 1 Jul 30, 2013 07:04 PM
Help with Applescript error watcoh Mac Basics and Help 0 Apr 29, 2013 05:15 PM
Applescript error - stripping file extension AlexFW Mac Programming 11 Feb 18, 2013 01:09 PM
AppleScript works but returns an error? TheMTtakeover Mac Programming 3 Jan 17, 2013 10:01 PM
Applescript Error ekulmail71 Mac Programming 0 Nov 7, 2012 03:04 AM

Forum Jump

All times are GMT -5. The time now is 07:15 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC