Automator实现右键百度翻译

打开Automator,新建service
接着

Paste_Image.png

第二步,选择run applescript

on run {input, parameters}
    set output to "http://fanyi.baidu.com/?aldtype=16047&tpltype=sigma#en/zh/" & urldecode(input as string)
    return output
    
end run
on urldecode(x)
    set cmd to "'require \"cgi\"; puts CGI.escape(STDIN.read.chomp).gsub(\"+\",\"%20\")'"
    do shell script "echo " & quoted form of x & " | ruby -e " & cmd
end urldecode

第三步,如图

Automator实现右键百度翻译_第1张图片
Paste_Image.png

使用是右键就可以了

Automator实现右键百度翻译_第2张图片
Paste_Image.png

同时给出一个朗文词典的办法,修改第二步的代码就可以了!

on run {input, parameters}
    set output to "http://www.ldoceonline.com/dictionary/" & input as string
    return output
end run

有道词典

on run {input, parameters}
    set output to ("http://m.youdao.com/dict?le=eng&q=" & input as string)
    return output
end run

当然啦,这些用popclip也可以实现,不过那个要跳转,比较麻烦!

你可能感兴趣的:(Automator实现右键百度翻译)