Using Alfred for Efficient Word Lookup with Eudic Dictionary
Eudic Dictionary is currently my only dictionary for word lookup, but the overall operation experience is still not efficient, so I plan to spend some time polishing it.
Complaints About Current Eudic
Before polishing, let me first complain about things I find annoying
- For word selection and lookup, if automatic word selection is enabled, word lookup icons will always be displayed everywhere, which is very annoying for someone who pursues simplicity like me. With manual word selection, every time I want to look up a word, I have to manually type the word again for searching.
- Cannot achieve one-click pronunciation - either choose automatic pronunciation after word lookup, or need cursor operations to select and trigger pronunciation.
Usage Flow Design
Since I want to polish it, let me first set a goal. The diagram below shows the operation flow I designed, which solves 2 pain points:
- After invoking Eudic Dictionary, no need to manually input the target word again
- One-click American pronunciation
Technology
- Apple Script to implement app operations for word lookup and pronunciation
- Alfred to implement getting cursor selection content and hotkeys
Eudic Settings
Disable hotkey settings
Automatic Word Search Execution
tell application "Eudic"
activate
show dic with word "{query}"
end tell
One-Click Pronunciation
on alfred_script(q)
tell application "Eudic"
activate
set windowName to the name of the front window
speak word with word windowName
end tell
end alfred_script
Note: Eudic’s one-click pronunciation is American pronunciation, which is exactly what I need. If it’s not, then this method cannot be used, and you would need to implement controlling cursor operations on GUI elements.
Final Alfred Workflow
Notes:
- The hotkeys are set this way because my current design uses
⌘ ⌥
combination for system-level shortcuts, and⌘ ⇧
combination for application-level shortcuts.E means eudic, s means speak
- The reason the first workflow needs to add launch is to bring the app to front. The online solution
set frontmost to true
doesn’t work.
Workflow download link: Click here
Final Result
The effect of the second one-click pronunciation cannot be demonstrated, experience it yourself.
AppleScript Usage Tips
During this polishing process, I also learned about Apple Script. There’s actually very little documentation available, so I’ll record some commonly used tips here.
Apple Suite
For individual apps, what actions we can perform depends on the Apple Suite. Open Script Editor, press ⌘ ⇧ O, select the specific app, and you can see the corresponding class properties and functions.
Log Printing
log hello
Variable Setting
set name11 to "1111"
Final Thoughts
Now word lookup is more efficient than before, Perfect!
Related Documentation
- AppleScript 入门:探索 macOS 自动化
- AppleScript Wiki
- https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html
- https://macscripter.net/viewtopic.php?id=24480
- http://hints.macworld.com/article.php?story=20060105082728937
- 小玩 Apple Script
- AppleScript学习笔记(一)初识AppleScript
- Zoom Window.applescript