获取Google-Chrome选择和当前网址,然后在Mail.app中撰写新电子邮件

时间:2014-04-01 20:24:46

标签: google-chrome email applescript automator

我(一个菜鸟和)试图把一个脚本放在一起

  1. 复制Chrome标签页中的所选文字
  2. 复制标签页
  3. 使用以下命令在OSX Mail.app中撰写新电子邮件:
    1. subject =看看这个,老板!
    2. 消息:网址+选择
  4. 我已经尝试过使用Automator服务(服务接收任何应用中的选定文本+#34;新邮件消息"模块),这对填充邮件正文非常有用,但没有相应的URL,它就是'几乎不可能最终回到文本的来源......

    这有什么意义吗?这样可以减少当前工作流程的时间(复制/粘贴...)。 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我对此采取了一个措施:

#!/bin/bash
# This successfully copies the highlighted text to the clipboard
chromeurl() {
    url=$(osascript <<EOT
        tell application "Google Chrome" to return URL of active tab of front window
EOT)
# & requires escaping for the xml
echo ${url/&/&amp;}
}

chrometext() {
    # Assign the clipboard to a variable
    # This avoids overwriting it, as "get copy" is the only way I know to get it out of chrome
    pbrevert=$(pbpaste)
    # Copy selected text in chrome 
    $(osascript <<EOT
        tell application "Google Chrome" to get copy selection of active tab of window 1
EOT)
    pbcapture="$(pbpaste)"

    # Revert clipboard
    echo $pbrevert | pbcopy

    echo $pbcapture
}

content="$(chromeurl) $(chrometext)"

echo $content

osascript -e "tell application \"Mail\" to make new outgoing message with properties {subject:\"Look at this, boss!\", content:\"$content\", visible:true}"

注意 - 它会执行您提到的内容,但不会将电子邮件作为前端焦点窗口:

我还使用Mathias Bynens将其转换为 .app - Appify ,将bash文件转换为 .app 文件。

Dropbox Link to .app