- 打开Automator,新建 服务
- 添加
运行AppleScript - 复制DicLog的内容到AppleScript中
- 保存
- 打开系统偏好设置>键盘>快捷键 找到刚刚保存的名字设置快捷键
- 选定文本,按快捷键。
- 所有查询的文本会自动保存到桌面上的DictLogger.txt
- 保存位置和名称可以自行修改脚本
| # © McUsr/MacUser06 2012 | |
| on run {input, parameters} | |
| set glossaryName to "DictLogger.txt" | |
| set AutomatorIcon to (a reference to file ((path to applications folder as text) & "Automator.app:Contents:Resources:Automator.icns")) | |
| # checks to see if the current selection contains anything valid | |
| considering diacriticals | |
| if first character of (input as text) is not in "abcdefghijklmnopqrstuvwxyz" then | |
| tell application "System Events" to set appname to name of first process whose frontmost is true | |
| using terms from application "Finder" | |
| tell application appname | |
| display dialog "The selection you tried to look up a dictionary definiton for contains non-valid characters. | |
| Please copy the selection you used into an empty text document to figure out what is wrong. | |
| Quitting for now…" with title "Dictionary Logging Service" buttons {"Ok"} default button 1 with icon AutomatorIcon | |
| end tell | |
| end using terms from | |
| return input | |
| end if | |
| end considering | |
| try | |
| open location "dict://" & input | |
| end try | |
| tell application "TextEdit" | |
| try | |
| set glossaryDoc to its document glossaryName | |
| on error | |
| set glossaryDoc to null | |
| end try | |
| end tell | |
| try | |
| set theF to quoted form of (POSIX path of (path to desktop folder as text) & glossaryName) | |
| end try | |
| set foundword to true | |
| try | |
| do shell script "test -f " & theF & " || touch " & theF | |
| set foundword to (do shell script "grep '^" & input & "$' " & theF & ">/dev/null && echo \"true\" || echo \"false\"") as boolean | |
| end try | |
| if not foundword then | |
| if glossaryDoc is not null then | |
| tell application "TextEdit" | |
| tell its document glossaryName | |
| make new paragraph at beginning of its text with data ((input as text) & linefeed) | |
| end tell | |
| save glossaryDoc | |
| end tell | |
| else | |
| try | |
| do shell script "export TMPFILE=`mktemp /tmp/${tempfoo}.XXXXXX` && cat " & theF & " >$TMPFILE ; echo " & input & ">|" & theF & " ; cat $TMPFILE >>" & theF | |
| end try | |
| end if | |
| end if | |
| do shell script "open -b \"com.apple.Dictionary\"" | |
| return input | |
| end run |