I can get this to work sporadically when running it from Script Debugger 4, and not at all from the Script Editor. Anyone see what I’m screwing up here?
--set theWord to the text returned of (display dialog "What word would you like to look up?" default answer "")
set theWord to "hasty"
set R to {Dict:missing value, Thes:missing value}
open location "dict:/// " & theWord
activate application "Dictionary"
delay 1
-- Dictionary remembers whether it was Dictionary or Thesaurus, set it to Dictionary.
tell application "System Events" to tell process "Dictionary" to tell window 1 to tell checkbox 2 to ((perform action) click)
delay 1
set R's Dict to paragraphs of copyContents(1)
delay 1
-- This gets us the Thesaurus window
tell application "System Events" to tell process "Dictionary" to tell window 1 to tell checkbox 3 to ((perform action) click)
delay 1
set R's Thes to paragraphs of copyContents(2)
on copyContents(n)
try
tell application "Dictionary"
activate
end tell
delay 0.5
tell application "System Events" to tell process "Dictionary" to tell window 1 to tell splitter group 1 to tell scroll area 1 to tell UI element 1 to tell group n to tell scroll area 1 to tell UI element 1 to set focused to true
delay 0.5
my do_menu("Dictionary", "Edit", "Select All")
my do_menu("Dictionary", "Edit", "Copy")
return the clipboard
on error E
return E
end try
end copyContents
on do_menu(app_name, menu_name, menu_item)
try
-- bring the target application to the front
tell application app_name
activate
end tell
tell application "System Events" to tell process app_name to tell menu bar 1 to tell menu bar item menu_name to tell menu menu_name to click menu item menu_item
return true
on error error_message
return false
end try
end do_menu