Getting the OS X Dictionary to work in certain applications

Hi,

I’m stuck with an application (Screenwriter 6) that won’t let me check definitions from OS X’s Dictionary with the keyboard shortcut “command-control-d”. The “search in Dictionary” item is also absent from the contextual menu in that application. It’s a major annoyance.

It isn’t because that keyboard shortcut is assigned to some other function of Screenwriter either.

I’ve tried to force the thing with this script. Please, don’t laugh.

tell application "System Events"
	set process_name to name of first process whose frontmost is true
end tell

delay 0.5

tell application "System Events"
	tell application process_name
		keystroke "d" using {command down, control down}
	end tell
end tell

tell me to activate

I have FastScripts, if that can help.

Zague

Something like this?

--set theWord to the text returned of (display dialog "What word would you like to look up?" default answer "")
set theWord to the clipboard -- if you are going to copy the word.
set Def to missing value
open location "dict:/// " & theWord
activate application "Dictionary"
delay 1
-- Dictionary remembers whether it was last at 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)
-- should now have page in dictionary.

That works. Thanks!

Now, is there a way to spare the copy to clipboard step and have the current text selection passed to the script?

I tried the following code but it gives inconsistent results. It’ll work a first time, then it’ll take like 30 seconds before it’ll accept a new word. Each time in between the Dictionary will show up with the word of the first time in its search field. This probably involves delays and I’m actually trying to tune them but I can’t seem to find the right value (given that something like 20 seconds would be counterproductive, of course). Maybe it’s a matter of their place in the script. I don’t know.

tell application "System Events"
	set process_name to name of first process whose frontmost is true
end tell

delay 1

tell application "System Events"
	tell application process_name
		keystroke "c" using command down
	end tell
end tell

Z