我花了一條縫在此:
#!/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/&/&}
}
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}"
NB - 它你所提到的,但不會使電子郵件前聚焦窗口:
我也把它的成.app使用Mathias Bynens的 - Appify ,它將bash文件轉換爲.app文件。
Dropbox Link to .app
也非常值得考慮看看:http://osxnotes.net/applescript.html – robstarbuck