Because the @red_menace suggests, the character of how this script known as is unclear. I’ve made the idea that it will likely be referred to as utilizing an Automator workflow that’s accessed by way of the script menu (i.e., within the Person’s Library > Scripts folder. In fact, changes will be made for various approaches.
The next ought to be positioned inside a “Run Applescript” motion.
use scripting additions
on run {enter, parameters}
inform software "System Occasions"
set frontApp to call of first software course of whose frontmost is true
finish inform
set oldClipboard to the clipboard
inform software frontApp
activate
inform software "System Occasions"
inform software course of frontApp
keystroke "c" utilizing command down
delay 0.1
finish inform
finish inform
set theWord to first phrase of (the clipboard as «class utf8»)
delay 0.1
finish inform
-- Log file path
set logPath to (POSIX path of (path to desktop)) & "dictionary_log"
do shell script "contact " & quoted type of logPath
-- Append the phrase to the log
do shell script "echo " & quoted type of theWord & " >> " & quoted type of logPath
-- Open Dictionary to that phrase
do shell script "open dict://" & quoted type of theWord
-- Restore clipboard
set the clipboard to oldClipboard
finish run
The additions to the OP script are as follows:
- Contains “use scripting additions” because the clipboard is a spotlight right here
- Will get and prompts the entrance software in order that the Cmd+C keystroke has one thing to work on
- Truncates after first phrase in order that the log file does not accumulate extraneous verbiage
- Explicitly use utf-8
I examined it on a couple of apps, together with Firefox and Dictionary itself, with out challenge.
