Hi all,
Recently I come across with a problem of finding out a way to make a highlighted word to “feed” into the
oxford advanced learner’s dictionary 7 (OALD7) in my mac. I know nothing about apple script ('cos I am a graduate student studying in public health …), and would like to ask, if anyone could give me an applescript to do the job or some possible templates so I could try
my very best to modify it ?
Currently I am using the default service manual’s shortcut to feed highlighted word into Dictionary in mac (default one), and using quicksilver to feed word into web-based dictionary (e.g. m-w.com) by a single key-combo. I wish I could do something similar in the OALD7…
Thanks all in advance!
Jake
The following works for the standard Dictionary app on 10.4, called from a FastScripts key combo.
Maybe you can adapt it for your needs.
Peter B.
tell application "System Events"
set process_name to name of first process whose frontmost is true
end tell
delay 0.3
tell application "System Events"
tell application process_name
keystroke "c" using command down
end tell
end tell
tell me to activate
delay 0.3
set look_up to the clipboard
if (count of look_up) is greater than 25 then
set look_up to ""
end if
tell application "Dictionary" to activate
tell application "System Events"
tell process "Dictionary"
keystroke "a" using command down
keystroke look_up
--keystroke (ASCII character 3)
end tell
end tell
Hi Peter,
It works!
However, do you know if that could be modify so:
-
I just need to highlight the word, but don’t have to copy it before I run the script?
ie. directly call the selection I 've made
-
An “enter” command at the end of the script? it did feed the word into the search field, but
to get the explanation in both OALD7 and Dictionary in mac, I need to press “enter”.
Nothing I can offer but a BIG THANKS to you for your help!
Jake
Jake:
Glad the script helped…
You shouldn’t need to copy the word by key command… just highlight and the script should do the rest.
Remove the comment (hyphens) from this line:
–keystroke (ASCII character 3)
… in the script, and the enter key should be pressed.
Let me know if it ain’t so. (Works here.)
Peter B.
Peter,
Well…I am using 10.5…is that the cause of the issue…?
I got a screencast of what I did using the dict as demo and what I got: http://www.screencast-o-matic.com/watch/cjf0Y7Vr9
It’s really weird… :rolleyes:
Jake
Against my better judgement, I tried twice to view the URL you posted, without luck.
So I have no way of knowing what problem you might be having.
Yes, Leopard may have an impact. I don’t have it to test with.
I think you should be able to modify the script to work.
Peter B.
Thanks Peter, I will try my best to modify it
jakekei,
You need to call the script using a HotKey app, Like Spark or FastScripts.
Then you select you text and call the script using a hot key.
It will not work by you selecting the text and then going to Script Editor to run the script.
In Peters Script, The App you are selecting the text from needs to stay in front.
Peter,
I modified the script a bit,
tell application "System Events"
set process_name to name of first process whose frontmost is true
delay 0.4
tell application process_name
set feed to the clipboard (keystroke "c" using command down)
end tell
end tell
tell application "Dictionary" to activate
tell application "System Events"
set value of text field 1 of group 1 of tool bar 1 of window "Dictionary" of application process "Dictionary" to feed
click button 1 of text field 1 of group 1 of tool bar 1 of window "Dictionary" of application process "Dictionary"
end tell
Mark,
Thanks Mark, now I can use the highlighted word and feed into the dictionary directly (using Peter’ script)
However when executing your modified script, I got a system error message:
"system events got an error : can’t set window “dictionary” of application process “dictionary” to “set value
of text field 1 of group 1 of tool bar 1 of window "dictionary" of application process "dictionary" to feed”.
for this line
“set value of text field 1 of group 1 of tool bar 1 of window “Dictionary” of application process “Dictionary” to feed”
I have no ideas what is going on …
Jake
Changed window “Dictionary” to window 1
tell application "System Events"
set process_name to name of first process whose frontmost is true
delay 0.4
tell application process_name
set feed to the clipboard (keystroke "c" using command down)
end tell
end tell
tell application "Dictionary" to activate
delay 0.4
tell application "System Events"
set value of text field 1 of group 1 of tool bar 1 of window 1 of application process "Dictionary" to feed
click button 1 of text field 1 of group 1 of tool bar 1 of window 1 of application process "Dictionary"
end tell
I’ve added 2 lines to Peter’ script and now I don’t have to press “enter” after that. :lol:
tell application "System Events"
set process_name to name of first process whose frontmost is true
end tell
delay 0.3
tell application "System Events"
tell application process_name
keystroke "c" using command down
end tell
end tell
tell me to activate
delay 0.3
set look_up to the clipboard
if (count of look_up) is greater than 25 then
set look_up to ""
end if
tell application "Dictionary" to activate
tell application "System Events"
tell process "dictionary"
keystroke "a" using command down
keystroke look_up
delay 0.5
keystroke return
end tell
end tell