Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'An AppleScript to highlight and dictate a document' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to highlight and dictate a document
Authored by: leenoble_uk on Aug 30, '05 12:35:05PM

Here's the missing script:
[code]
-- set the speed factor to any number you like.
-- this will be the default value, you will
-- have a chance to change each time you run the script.
-- Use decimal between 0 and 1 to slow down
-- Use positive integers to increase speed
property speedFactor : 2 -- my default typing speed
property speak : true
property paraColour : {65000, 2300, 2300}
property wordColour : {2300, 2300, 65000}
property docBounds : {0, 22, 1151, 280}

tell application (path to frontmost application as string)
activate
tell application "System Events"
set GUIenabled to get UI elements enabled
if GUIenabled = false then
display dialog "This script requires you to enable access for assistive devices in the Universal Access preference pane. You have not done so." buttons {"OK"} default button 1 with icon 0 giving up after 5
return
end if
set theProcess to item 1 of (every process whose frontmost is true)
if theProcess is not "TextEdit" then
set oldClipboard to the clipboard
try
tell theProcess to keystroke "c" using command down
delay 1 --give it time to update
set selectedText to (the clipboard) as string
set the clipboard to oldClipboard
on error msg
set selectedText to missing value
set the clipboard to oldClipboard
display dialog msg with icon 0
end try
tell application "TextEdit"
if (exists of document 1) is false then
set newDoc to (make new document at beginning of documents)
end if
set text of document 1 to selectedText
end tell
end if
end tell
if selectedText = missing value then
display dialog "Either the AppleScript GUI syntax does not work for this app, or the selection could not be converted to the appropriate format" buttons {"OK"} default button 1 with icon 0 giving up after 5
else if selectedText = "" then
display dialog "You need to select some text to put in the memo!" buttons {"OK"} default button 1 with icon 0 giving up after 5
end if
set newSpeedFactor to text returned of (display dialog "Set the dictation speed:" & (return as text) & "(2 is my normal typing speed)" default answer speedFactor)
try
set newSpeedFactor to newSpeedFactor as number
set speedFactor to newSpeedFactor
end try
end tell

tell application "TextEdit"
set bounds of window 1 to docBounds
set fullText to (text of document 1)
set paras to (paragraphs of fullText)
set theColour to color of paragraph 1 of document 1
set theSize to size of paragraph 1 of document 1
set lastPara to 1
repeat with i from 1 to count of paras
try
set thisPara to (paragraph i of fullText)
if (thisPara is not (ASCII character 10)) and (thisPara is not "") then
set displayText to (paragraph i of fullText)
if i is greater than 1 then
set displayText to (displayText & (return as text) & (paragraph (lastPara) of fullText))
end if
set the text of document 1 to displayText
try
set color of (paragraph 1 of document 1) to paraColour
try
set color of (paragraph 2 of document 1) to {35000, 35000, 35000}
end try
set size of (paragraph 1 of document 1) to 18
end try

set theWords to words of (paragraph i of fullText)
repeat with j from 1 to (count of theWords)
set theWordChars to characters of (word j of paragraph i of fullText)
set wordCharNum to count of theWordChars
set silencePeriod to ((wordCharNum / 3) / speedFactor)
set color of (word j of paragraph 1 of document 1) to wordColour
if j is greater than 1 then
set color of (word (j - 1) of paragraph 1 of document 1) to paraColour
end if
if speak is true then
say (((word j of paragraph i of fullText) & "[[slnc " & (round (silencePeriod * 1000) rounding as taught in school) & "]]") as text)
else
say (("[[slnc " & (round (silencePeriod * 1000) rounding as taught in school) & "]]") as text)
end if
end repeat
set lastPara to i
else
say "New Section"
end if
say "New paragraph"
on error
if (exists of document 1) is false then
make new document at beginning of documents
set bounds of window 1 to docBounds
end if
try
set color of paragraph 1 of document 1 to theColour
set size of paragraph 1 of document 1 to theSize
set text of document 1 to fullText
end try
exit repeat
end try
end repeat
try
set color of paragraph 1 of document 1 to theColour
set size of paragraph 1 of document 1 to theSize
set text of document 1 to fullText
end try
end tell
[/code]

Thanks to previous submission which explains how to grab selected text from any app. This has a few enhancements allowing you to change the speed each time you run it and resizing the dictation window. This however is specific to my machine and you might want to fiddle with the parameters at the top of the script. The speech may not have worked because I submitted it set to false before.

---
So, I said ... well, I can't actually remember exactly what I said. But it was one of the most enormously cruel and frighteningly witty put downs ever.



[ Reply to This | # ]