題:
在終端的Dictionary.app中查找單詞
denis
2013-04-29 14:48:54 UTC
view on stackexchange narkive permalink

是否有bash或applescript在終端窗口的 /Applications/Dictionary.app 中查找單詞?

  open -a / Applications / Dictionary .app / --args word  

忽略--args,說“輸入一個單詞來查找”

Mac Dictionary改進建議 ⌃控制 kbd> ⌘命令 kbd> D kbd>,但是我希望啟動完整的應用程序,而不僅僅是小型彈出窗口。

只需單擊彈出窗口中詞典的名稱即可在詞典應用程序中打開搜索,而不是“更多”按鈕。
謝謝大家,[there's_more_than_one_way_to_skin_a_cat](http://en.wiktionary.org/wiki/there's_more_than_one_way_to_skin_a_cat)
十 答案:
gentmatt
2013-04-29 15:53:23 UTC
view on stackexchange narkive permalink

您可以使用...

  open dict:// my_word  

...這將打開Dictionary應用程序並查找字符串 my_word 。如果要使用多個單詞,請使用 open dict://“ Big Bang Theory”

終端中沒有輸出。

謝謝。是否有打開的magicprefix列表:...某處?
@Denis我不知道專門收集open的未記錄命令選項的源。但一般來說,http://hints.macworld.com/是眾所周知的隱藏寶石來源。我還曾經知道一個不同的來源,該來源收集未記錄的“默認寫入”命令,但我不記得它只是知道而Google也沒有幫助我...
不久前,我在SuperUser上做了“ open”的簡短摘要http://superuser.com/questions/4368/os-x-equivalent-of-windows-run-box/4383#4383
@denis系統維護著一個包含所有已安裝的所有應用程序已告訴其如何處理的所有前綴的數據庫。如果您能想到了解該花絮的實際用途,那麼提出一個完整的問題將是非常棒的。
Josh Hunt
2013-04-29 16:22:43 UTC
view on stackexchange narkive permalink

使用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

enter image description here

查看帖子有關在整個終端上對其進行訪問的更多說明。

我使用了此腳本,但是輸出中沒有換行符,它看起來像這樣:http://i.imgur.com/ooAwQCA.png(在OS X 10.9上)。
我也沒有在輸出中換行。檢查`print repr(dictresult.encode('utf-8'))`會顯示以下內容:`'dictation | d \ xc9 \ xaak \ xcb \ x88te \ xc9 \ xaa \ xca \ x83(\xc9 \ x99)n |\ xe2 \ x96 \ xb6名詞[mass名詞] 1指示要鍵入,寫下或記錄在磁帶上的單詞的動作:字母的聽寫。\ xe2 \ x80 \ xa2刪除一段由老師決定的段落的活動,以作為測試拼寫,寫作或語言技能的依據:\ xe2 \ x80 \ xa2被指定的單詞:工作將包括聽寫,起草...
我添加了一些字符串替換來模擬換行符。雖然我沒有對其進行廣泛的測試,但似乎可以正常工作:https://gist.github.com/lambdamusic/bdd56b25a5f547599f7f
這似乎不再起作用。
peccu
2017-11-16 11:40:56 UTC
view on stackexchange narkive permalink

我找到了使用Swift 4的解決方案。

 #!/ usr / bin / swift
進口基金會

如果(CommandLine.argc < 2){
    打印(“用法:字典字”)
}其他{
    讓參數= CommandLine.arguments [1]
    讓結果= DCSCopyTextDefinition(無,參數作為CFString,CFRangeMake(0,arguments.count))?. takeRetainedValue()作為字符串?
    打印(結果??“”)
}
 
  1. 將其另存為 dict.swift
  2. 通過 chmod + x dict.swift
  3. 添加權限
  4. 查找字典
    • 使用解釋器 ./ dict.swift word
    • 由編譯器 swiftc dict.swift 構建並運行 ./ dict word
  5. ol>
Lri
2013-04-29 16:03:56 UTC
view on stackexchange narkive permalink

我也建議使用 open dict:// word ,但是Google的字典API也使用了《新牛津美國字典》:

 #!/ usr / bin / env ruby​​require“ 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 |將單詞+“:” +“ '“)}}  
該Google API已棄用,並返回404。看起來http://www.dictionaryapi.com/可以工作,只需要登錄即可。
Huy Tran
2015-10-13 02:38:12 UTC
view on stackexchange narkive permalink

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() 
odlp
2016-11-20 22:33:56 UTC
view on stackexchange narkive permalink

嘗試 Dictionary OSX(在遇到其他答案並希望使用非Python解決方案後,我進行了此操作)。它使用 Dictionary.app 中的定義。

 字典貓
#cat 1 | kat |▶名詞1小型馴養的食肉哺乳動物,毛皮柔軟。
 

它使用 DictionaryKit,這是OSX上可用的私有Dictionary Services的包裝。有關如何在 NSHipster上工作的有趣背景信息。

aztack
2018-03-07 09:50:13 UTC
view on stackexchange narkive permalink

簽出此github回購: https://github.com/aztack/osx-dictionary

安裝:簡單安裝https://raw.githubusercontent.com/takumakei/osx-dictionary/master/osx-dictionary.rb --HEAD

enter image description here

user28958
2015-04-20 03:00:18 UTC
view on stackexchange narkive permalink

我偶然發現了這篇文章,尋找類似的內容。對可用的選項不滿意,因此製作了簡單的腳本。它是一個基於終端的詞庫,具有文本到語音功能。可能很有趣...

https://github.com/aefty/thes

kcidkcus
2015-11-07 22:35:03 UTC
view on stackexchange narkive permalink

在下面的線程中查找如何在終端中使用Dictionary.app: https://discussions.apple.com/thread/2679911?start=0&tstart=0

關於“與眾不同”的答案不僅需要鏈接。可以包含鏈接,但請在答案中進行總結或摘錄。這個想法是使答案獨立存在。
Shalom Friss
2020-01-07 20:49:35 UTC
view on stackexchange narkive permalink

這裡是我放在一起的超級簡單的東西。

歡迎詢問不同!儘管從理論上講這可能會回答問題,但[最好](//meta.stackoverflow.com/q/8259)在此處包括答案的基本部分,並提供鏈接以供參考。如果鏈接斷開,答案將一文不值。


該問答將自動從英語翻譯而來。原始內容可在stackexchange上找到,我們感謝它分發的cc by-sa 3.0許可。
Loading...