am trying to write scripts to automatically highlight text (for example in keynote) and then have that text read via the speech engine already in tiger…anyone tried that? thx twb
Model: ibook g4
AppleScript: 2
Browser: Internet Explorer 6.0
Operating System: Mac OS X (10.4)
Getting text to speak is fairly simple. If the application has a way to script the text into a string, that is best, but you can GUI script [command] copy as well. When you have the text as a variable,
tell application "TextEdit" to set thetext to words of text of document 1
tell application "SpeakableItems" to say thetext as string
Since the ‘say’ command is from the User Interaction Suite of Standard Additions, it shouldn’t really be necessary to target any app (apart from the one providing the text):
tell application "TextEdit" to say (get document 1's text)
The AS implementation is better in some apps than in others. (One might be forgiven for assuming that Apple’s own applications would provide the best examples but, sadly, that’s not always the case.) For example, you could progressively select a paragraph at a time in a number of third-party apps, such as Tex-Edit Plus, something like this:
tell application "Tex-Edit Plus" to tell document 1
activate
repeat with n from 1 to count paragraphs
select paragraph n
say (get selection)
end repeat
select insertion point after contents (* deselect text *)
end tell
(If you prefer to process just a line at a time, simply replace “paragraph[s]” with “line[s]” - or, for word-by-word execution, “word[s]”.)