FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister   ProfileProfile    Log inLog in   RSS Feed

Need help making a script better :p

 
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Mac
View previous topic :: View next topic  
Author Message
Ronnieronson
Junior Member


Joined: 12 Apr 2005
Posts: 37

PostPosted: Sun Apr 17, 2005 7:06 pm    Post subject: Need help making a script better :p Reply with quote

Ok heres the deal.
As you might have noticed I've knocked up a little script for making your mac speak a phrase typed in by the phone user.

Now I want to make it so that the phone user can select which voice is used.
I've tryed a few ways round this but im afraid im still shaking the dust off my applescripting skills, and im not getting far, fast.

Heres what I have so far:

property voicelist : {"Agnes", "Albert", "Bruce", "Fred", "Junior", "Kathy", "Princess", "Ralph", "Victoria", "Zarvox"}

try
tell application "SEC Helper"
enter list mode title "Voices" items voicelist item selected "displaychoice"
end tell
on error
beep
end try

on displaychoice(itemIndex)
try
tell application "SEC Helper"
show screen message " " & (item itemIndex of voicelist)
end tell
on error
beep
end try
return false
end displaychoice


...Currently all it does is take the value from the "voicelist" and pass that back as a screen message - I need to somehow add in the say command a la:

tell application "Finder"
say "" & result_text using "" & (item itemIndex of voicelist)

so that the voice is correctly selected.
Im really stuck on this one - any help would be greatly appreciated!

Ive attatched the two clicker files im using at the moment - incase anyone fancies digging around in my code :P


Last edited by Ronnieronson on Tue Apr 19, 2005 11:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Sun Apr 17, 2005 7:21 pm    Post subject: Reply with quote

This seems to work (in Script Editor):

say "hello" using ("Albert" as string)

I'm not sure what the problem for you is, but you may want to try this:

say result_text using (item itemIndex of voicelist as string)

What's the problem?

Best.
--
Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ronnieronson
Junior Member


Joined: 12 Apr 2005
Posts: 37

PostPosted: Sun Apr 17, 2005 7:39 pm    Post subject: Reply with quote

hmmm dunno - cant seem to figure it out, tried it the way you suggested, but still nothin.

I think its the order of my script... seems a little messed up.

its really bugging me now - been sat staring at my screen for the last 2hours trying to get it worked out in my head, but whatever I do seems not to work :(
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Sun Apr 17, 2005 7:51 pm    Post subject: Reply with quote

Ok. I had a look at your script. There's a couple of problems with it, the most serious one being your assumption that the call "enter list mode" would block until an item has been selected.

Here's an outline on how to fix it.

Change the text field handler to not speak (just push the voice list):

[code:1]
on affirmative_textfield_response(result_text)
set the_text to result_text

try
tell application "SEC Helper"
enter list mode title "My List" items my_list item selected "item_was_selected"
end tell
on error
beep
end try

return false
end affirmative_textfield_response
[/code:1]

Add a list selection handler:

[code:1]
on item_was_selected(itemIndex)
try
tell application "Finder"
say "" & the_text using "" & (item itemIndex of my_list)
end tell
end try
return false
end item_was_selected
[/code:1]

Finally, as indicated in the handlers above, we're going to need a property to store the chosen text in (the_text).

This should work much better.

Best.
--
Jonas

PS. Clicker-scripts should never block, and calls into Clicker won't block. Results are brought back to the scripts through call-backs.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ronnieronson
Junior Member


Joined: 12 Apr 2005
Posts: 37

PostPosted: Sun Apr 17, 2005 8:12 pm    Post subject: Reply with quote

:roll: I think I must have done something wrong, made the relevant changes, but nothing happens.. no error beeps... nothing.

Also with the_text, do you mean it needs setting up as a property at the start of the script?

TY Jonas for your help :lol: :D :o :) :P :mrgreen: :mrgreen:


Last edited by Ronnieronson on Tue Apr 19, 2005 11:58 pm; edited 1 time in total
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Sun Apr 17, 2005 10:54 pm    Post subject: Reply with quote

yes, you must declare the_text for it to be global (which is what you want, so it can be shared between the call-back handlers):

property the_text : ""

Best.
--
Jonas

[quote="Ronnieronson"]:roll: I think I must have done something wrong, made the relevant changes, but nothing happens.. no error beeps... nothing.

Also with the_text, do you mean it needs setting up as a property at the start of the script?

TY Jonas for your help :lol: :D :o :) :P :mrgreen: :mrgreen:[/quote]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ronnieronson
Junior Member


Joined: 12 Apr 2005
Posts: 37

PostPosted: Sun Apr 17, 2005 11:48 pm    Post subject: Reply with quote

well its not kicking out any errors, but its not working either.
For some reason it seems that the input text is not being spoken (in any voice - let alone one defined from the list).

I dunno if you can figure (or anyone else for that matter) it out, Jonas, but incase you fancy a look in, Ive included the most recent version of the script with your suggested modifications included.

:?

EDIT:

Messed around with the script - replacing the speak function with a display dialog box, for both the text to be spoken, and another for the voice to be used.
It seems that the text is being stored correctly within the variable the_text, but for some reason the voice option chosen is not registering anywhere.
At least Ive narrowed it down, so it might not be quite so hard to fix :?:

EDIT: EDIT:

Stupid me - forgot to change mylist to voicelist in one of the lines.
It seems both variables are being passed back correctly - now to get my mac talking in the right accent :P

EDIT: EDIT: EDIT:
Included my working file which returns the correct values by way of a popup dialog.... nearly there :D

EDIT: EDIT: EDIT: EDIT:
Hoooooooorah!!! its only taken me a whole day to get it sussed out, but its finally working!
Thanks for all your help Jonas!
Back to top
View user's profile Send private message
iNemo
Newbie


Joined: 06 Nov 2004
Posts: 12
Location: In a Field.

PostPosted: Tue Apr 19, 2005 4:42 pm    Post subject: Reply with quote

Can you post the updated script for us?

Caius
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Ronnieronson
Junior Member


Joined: 12 Apr 2005
Posts: 37

PostPosted: Tue Apr 19, 2005 11:52 pm    Post subject: Reply with quote

[quote="iNemo"]Can you post the updated script for us?

Caius[/quote]

Caius: Check the other forum topic - it is posted in it's own thread :D

Enjoy :D
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Mac All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group