是否有bash或applescript在終端窗口的 /Applications/Dictionary.app
中查找單詞?
open -a / Applications / Dictionary .app / --args word
忽略--args,說“輸入一個單詞來查找”
Mac Dictionary改進建議 ⌃控制 kbd> ⌘命令 kbd> D kbd>,但是我希望啟動完整的應用程序,而不僅僅是小型彈出窗口。
是否有bash或applescript在終端窗口的 /Applications/Dictionary.app
中查找單詞?
open -a / Applications / Dictionary .app / --args word
忽略--args,說“輸入一個單詞來查找”
Mac Dictionary改進建議 ⌃控制 kbd> ⌘命令 kbd> D kbd>,但是我希望啟動完整的應用程序,而不僅僅是小型彈出窗口。
您可以使用...
open dict:// my_word
...這將打開Dictionary應用程序並查找字符串 my_word
。如果要使用多個單詞,請使用 open dict://“ Big Bang Theory”
。
終端中沒有輸出。
使用Python Objective-C綁定,您可以創建一個小的python腳本,以從內置的OS X字典中獲取它。 這裡有一篇帖子,詳細介紹了此腳本”
#!/ usr / bin / pythonimport Sysfrom DictionaryServices import * def main():嘗試:searchword = sys.argv [ 1] .decode('utf-8'),但IndexError:errmsg ='您沒有輸入要在字典中查找的任何術語。 print errmsg sys.exit()wordrange =(0,len(searchword))dictresult = DCSCopyTextDefinition(None,searchword,wordrange),如果不是dictresult:errmsg =“在字典中找不到'%s'。”%(searchword)print errmsg .encode('utf-8')else:如果__name__ =='__main__':main()
將其保存到 dict.py
,然後只需運行 python dict.py dictation
查看帖子有關在整個終端上對其進行訪問的更多說明。
我找到了使用Swift 4的解決方案。
#!/ usr / bin / swift
進口基金會
如果(CommandLine.argc < 2){
打印(“用法:字典字”)
}其他{
讓參數= CommandLine.arguments [1]
讓結果= DCSCopyTextDefinition(無,參數作為CFString,CFRangeMake(0,arguments.count))?. takeRetainedValue()作為字符串?
打印(結果??“”)
}
dict.swift
chmod + x dict.swift
./ dict.swift word
swiftc dict.swift
構建並運行 ./ dict word
我也建議使用 open dict:// word
,但是Google的字典API也使用了《新牛津美國字典》:
#!/ usr / bin / env rubyrequire“ open-uri” require“ json” require“ cgi” ARGV.each {| word |響應=打開(“ http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=#{CGI.escape(word)}&sl=en&tl=en&restrict=pr,de“)。讀取結果= JSON.parse(response.sub(/dict_api.callbacks.id100 \(/,“”).sub(/,200,null \)$ /,“”))接下來,除非result [“ primaries”]結果[“ primaries“] [0] [” entries“]。select {| e | e [“ type”] ==“含義”} .each {| entry |將單詞+“:” +“ '“)}}
David Perace回答的更新代碼,添加了一些顏色和新行:
#!/ usr / bin / python#-*-編碼:utf-8-*-import sysimport refrom DictionaryServices import * class bcolors:HEADER ='\ 033 [95m'OKBLUE ='\ 033 [94m'OKGREEN ='\ 033 [92m'WARNING ='\ 033 [93m'FAIL ='\ 033 [91m'ENDC =' \ 033 [0m'BOLD ='\ 033 [1m'UNDERLINE ='\ 033 [4m'def main():try:searchword = sys.argv [1] .decode('utf-8')除了IndexError:errmsg = “您沒有輸入要在字典中查找的任何術語。”打印errmsg sys.exit()wordrange =(0,len(searchword))dictresult = DCSCopyTextDefinition(None,searchword,wordrange),如果不是dictresult:errmsg =“在字典中找不到'%s'。 %(搜索詞)打印errmsg.encode('utf-8')else:結果= dictresult.encode('utf-8')結果= re.sub(r'\ |(。+?)\ |',bcolors。 HEADER + r'/ \ 1 /'+ bcolors.ENDC,結果)結果= re.sub(r'▶','\ n \ n'+ bcolors.FAIL +'▶'+ bcolors.ENDC,結果)結果= re.sub(r'•','\ n'+ bcolors.OKGREEN +'•'+ bcolors.ENDC,結果)result = re.sub(r'('|“)(。+?)('|” )',bcolors。警告+ r'“ \ 2”'+ bcolors.ENDC,結果)打印結果if __name__ =='__main__':main()
嘗試 Dictionary OSX(在遇到其他答案並希望使用非Python解決方案後,我進行了此操作)。它使用 Dictionary.app
中的定義。
字典貓
#cat 1 | kat |▶名詞1小型馴養的食肉哺乳動物,毛皮柔軟。
它使用 DictionaryKit,這是OSX上可用的私有Dictionary Services的包裝。有關如何在 NSHipster上工作的有趣背景信息。
簽出此github回購: https://github.com/aztack/osx-dictionary
安裝:簡單安裝https://raw.githubusercontent.com/takumakei/osx-dictionary/master/osx-dictionary.rb --HEAD
我偶然發現了這篇文章,尋找類似的內容。對可用的選項不滿意,因此製作了簡單的腳本。它是一個基於終端的詞庫,具有文本到語音功能。可能很有趣...
在下面的線程中查找如何在終端中使用Dictionary.app: https://discussions.apple.com/thread/2679911?start=0&tstart=0
這裡是我放在一起的超級簡單的東西。