Skip to content

Commit

Permalink
update 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
whyliam committed May 6, 2015
1 parent d75a23f commit 89469fa
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 23 deletions.
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
# whyliam.workflows.youdao
---

有道翻译 workflow v1.0.0
有道翻译 workflow v1.1.0

默认快捷键 "cd",多个翻译结果,回车 即可以在有道词典的页面中查询输入的单词
默认快捷键 "cd",查看翻译结果

1. 英译中
2. 英译中
3. 翻译短语句子
4. 打开有道翻译页面,查看详细内容
5. 直接在打出翻译结果

### [下载](https://github.com/samqiu/Youdao.alfredworkflow/blob/master/Youdao.alfredworkflow)
[下载](https://github.com/liszd/whyliam.workflows.youdao/blob/master/whyliam.workflows.youdao.alfredworkflow?raw=true)

## Demo

![](http://ww1.sinaimg.cn/large/48910e01gw1ertn14ua8bg213m0khx5t.gif)
#### 英译中

![](http://ww2.sinaimg.cn/large/48910e01gw1erucr05z85g213p0kbqhn.gif)

#### 英译中

![](http://ww2.sinaimg.cn/large/48910e01gw1erucrd5tnmg213p0kbk6q.gif)

#### 翻译短语

![](http://ww2.sinaimg.cn/large/48910e01gw1erucrvb9a8g213p0kbqhn.gif)

#### 打开有道翻译页面

![](http://ww4.sinaimg.cn/large/48910e01gw1erucsmvtkgg213l0kaqq2.gif)

#### 直接打印结果

![](http://ww3.sinaimg.cn/large/48910e01gw1eructbvt9rg213p0jh0wi.gif)

---

Expand Down
181 changes: 169 additions & 12 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,54 @@
<string>Tools</string>
<key>connections</key>
<dict>
<key>27E60581-8105-41DD-8E29-4FE811179098</key>
<array>
<dict>
<key>destinationuid</key>
<string>DBA62127-3B78-4B80-B82B-1C6AEC393003</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
</dict>
</array>
<key>7C1ABC41-3B36-401F-96C7-30BCB39181FF</key>
<array>
<dict>
<key>destinationuid</key>
<string>0907BEF4-816F-48FF-B157-03F5C2AACEAB</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
</dict>
</array>
<key>91C343E7-50D8-4B0D-9034-1C16C20DA8D4</key>
<array>
<dict>
<key>destinationuid</key>
<string>E5E934DB-DBAC-4D0C-9AB0-ADAF62C5640B</string>
<string>9D65478B-1DB1-4198-B977-D538BCA74A4A</string>
<key>modifiers</key>
<integer>262144</integer>
<key>modifiersubtext</key>
<string>从有道网页打开</string>
</dict>
<dict>
<key>destinationuid</key>
<string>27E60581-8105-41DD-8E29-4FE811179098</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
</dict>
<dict>
<key>destinationuid</key>
<string>7C1ABC41-3B36-401F-96C7-30BCB39181FF</string>
<key>modifiers</key>
<integer>1048576</integer>
<key>modifiersubtext</key>
<string>直接打印</string>
</dict>
</array>
</dict>
<key>createdby</key>
Expand All @@ -30,13 +68,59 @@
<string>Youdao</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>applescript</key>
<string>on alfred_script(q)
# get default browser name see: https://discussions.apple.com/thread/4570295?start=0&amp;tstart=0
set browserName to do shell script "export VERSIONER_PERL_PREFER_32_BIT=yes; perl -MMac::InternetConfig -le 'print +(GetICHelper \"http\")[1]'"
set AppleScript's text item delimiters to {","}
set urlD to text item 1 of q
if ((contents of browserName) is equal to "Google Chrome") then
tell application browserName
tell (make new window )
activate
end tell
end tell
tell application "Google Chrome" to set URL of active tab of front window to urlD
else if ((contents of browserName) is equal to "Safari") then
# 新建窗口
tell application browserName
make new document at end of documents
end tell
# 设置窗口位置
tell application "Safari"
activate
end tell
# 打开 URL
tell application "Safari" to set URL of front document to urlD
end if
end alfred_script</string>
<key>cachescript</key>
<false/>
</dict>
<key>type</key>
<string>alfred.workflow.action.applescript</string>
<key>uid</key>
<string>9D65478B-1DB1-4198-B977-D538BCA74A4A</string>
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>127</integer>
<integer>7</integer>
<key>keyword</key>
<string>yd</string>
<key>queuedelaycustom</key>
Expand Down Expand Up @@ -70,37 +154,110 @@
<dict>
<key>config</key>
<dict>
<key>plusspaces</key>
<key>autopaste</key>
<false/>
<key>url</key>
<key>clipboardtext</key>
<string>{query}</string>
<key>utf8</key>
</dict>
<key>type</key>
<string>alfred.workflow.output.clipboard</string>
<key>uid</key>
<string>DBA62127-3B78-4B80-B82B-1C6AEC393003</string>
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>68</integer>
<key>script</key>
<string>/usr/bin/python splitargs.py "{query}" 1</string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>27E60581-8105-41DD-8E29-4FE811179098</string>
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>autopaste</key>
<true/>
<key>clipboardtext</key>
<string>{query}</string>
</dict>
<key>type</key>
<string>alfred.workflow.output.clipboard</string>
<key>uid</key>
<string>0907BEF4-816F-48FF-B157-03F5C2AACEAB</string>
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>68</integer>
<key>script</key>
<string>/usr/bin/python splitargs.py "{query}" 1</string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>E5E934DB-DBAC-4D0C-9AB0-ADAF62C5640B</string>
<string>7C1ABC41-3B36-401F-96C7-30BCB39181FF</string>
<key>version</key>
<integer>0</integer>
</dict>
</array>
<key>readme</key>
<string></string>
<string>有道翻译 workflow v1.0.0
默认快捷键 "cd",多个翻译结果,回车 即可以在有道词典的页面中查询输入的单词。</string>
<key>uidata</key>
<dict>
<key>0907BEF4-816F-48FF-B157-03F5C2AACEAB</key>
<dict>
<key>ypos</key>
<real>370</real>
</dict>
<key>27E60581-8105-41DD-8E29-4FE811179098</key>
<dict>
<key>ypos</key>
<real>250</real>
</dict>
<key>7C1ABC41-3B36-401F-96C7-30BCB39181FF</key>
<dict>
<key>ypos</key>
<real>370</real>
</dict>
<key>91C343E7-50D8-4B0D-9034-1C16C20DA8D4</key>
<dict>
<key>ypos</key>
<real>10</real>
<real>120</real>
</dict>
<key>9D65478B-1DB1-4198-B977-D538BCA74A4A</key>
<dict>
<key>ypos</key>
<real>30</real>
</dict>
<key>E5E934DB-DBAC-4D0C-9AB0-ADAF62C5640B</key>
<key>DBA62127-3B78-4B80-B82B-1C6AEC393003</key>
<dict>
<key>ypos</key>
<real>10</real>
<real>250</real>
</dict>
</dict>
<key>webaddress</key>
<string>youdao.com</string>
<string>https://github.com/liszd/whyliam.workflows.youdao</string>
</dict>
</plist>
19 changes: 19 additions & 0 deletions splitargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
import sys
from workflow import Workflow

reload(sys)
sys.setdefaultencoding('utf8')


def getargs(wf):
query = sys.argv[1]
query = query.split(',')
part = sys.argv[2]
part = int(part)
print query[part]
return 0

if __name__ == '__main__':
wf = Workflow()
sys.exit(wf.run(getargs))
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
Binary file not shown.
14 changes: 9 additions & 5 deletions youdao.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_web_data(query):

def main(wf):

query = wf.args[0].strip()
query = wf.args[0].strip().replace("\\", "")

if not query:
wf.add_item('有道翻译')
Expand All @@ -41,31 +41,35 @@ def main(wf):

if title != query:
subtitle = '翻译结果'
arg = url + "," + title
wf.add_item(
title=title, subtitle=subtitle, arg=url, valid=True, icon=ICON_DEFAULT)
title=title, subtitle=subtitle, arg=arg, valid=True, icon=ICON_DEFAULT)

# '简明释意'
if u'basic' in s.keys():
for be in range(len(s["basic"]["explains"])):
title = s["basic"]["explains"][be]
subtitle = '简明释意'
arg = url + "," + title
wf.add_item(
title=title, subtitle=subtitle, arg=url, valid=True, icon=ICON_BASIC)
title=title, subtitle=subtitle, arg=arg, valid=True, icon=ICON_BASIC)

# '网络翻译'
if u'web' in s.keys():
for w in range(len(s["web"])):
title = s["web"][w]["key"]
title = ''.join(title).encode("UTF-8")
subtitle = '网络翻译: ' + s["web"][w]["key"]
arg = url + "," + title
wf.add_item(
title=title, subtitle=subtitle, arg=url, valid=True, icon=ICON_WEB)
title=title, subtitle=subtitle, arg=arg, valid=True, icon=ICON_WEB)

else:
title = '有道也翻译不出来了'
subtitle = '尝试一下去网站搜索'
arg = url + "," + title
wf.add_item(
title=title, subtitle=subtitle, arg=url, valid=True, icon=ICON_DEFAULT)
title=title, subtitle=subtitle, arg=arg, valid=True, icon=ICON_DEFAULT)

wf.send_feedback()

Expand Down

0 comments on commit 89469fa

Please sign in to comment.