on displayErrorMessage(s)
display dialog (s) buttons {\"OK\"} default button \"OK\" with icon caution
end displayErrorMessage
property whiteSpaceAndNewlineCharacterSet : {tab, linefeed, return, space, character id 133}
on trim(someText)
repeat until first character of someText is not in whiteSpaceAndNewlineCharacterSet
set someText to text 2 thru -1 of someText
end repeat
repeat until last character of someText is not in whiteSpaceAndNewlineCharacterSet
set someText to text 1 thru -2 of someText
end repeat
return someText
end trim
global pageURL
global pageTitle
global selectedText
tell application \"Google Chrome\"
try
copy selection of (active tab) of window 1
set pageURL to (get URL of (active tab) of window 1)
set pageTitle to (get title of (active tab) of window 1)
on error errorMessage
displayErrorMessage(\"ERROR ENCOUNTERED\") of me
return
end try
end tell
tell application \"System Events\"
keystroke \"c\" using {command down}
set selectedText to (the clipboard as text)
end tell
set selectedText to trim(selectedText)
tell application \"MarsEdit\"
make new document
tell document 1
set title to pageTitle
set link to pageURL
if pageURL contains \"vimeo.com\" then
set idCode to text 18 thru 25 of pageURL
set s to \"[vimeo \" & idCode & \" 450 255]
\"
set s to s & \"via <a href=\\"http://vimeo.com/\" & idCode & \"\\" target=\\"_blank\\">vimeo.com</a>\"
set body to s
else if pageURL contains \"youtube.com\" then
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to \"v=\"
set idCode to text item 2 of pageURL
set AppleScript's text item delimiters to oldDelims
if idCode contains \"&\" then
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to \"&\"
set idCode to text item 1 of idCode
set AppleScript's text item delimiters to oldDelims
end if
set s to \"[youtube \" & idCode & \" 450 275]
\"
set s to s & \"via <a href=\\"http://www.youtube.com/watch?v=\" & idCode & \"\\" target=\\"_blank\\">youtube.com</a>\"
set body to s
else
set unescapedURL to do shell script \"perl -e 'use URI::Escape; print uri_unescape(\\"\" & pageURL & \"\\")';\"
set pageURL to unescapedURL
if pageURL contains \"?utm\" then
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to \"?utm\"
set pageURL to text item 1 of pageURL
set AppleScript's text item delimiters to oldDelims
end if
set s to \"<a href=\\"\" & pageURL & \"\\" target=\\"_blank\\"></a>
\"
set s to s & \"<blockquote>\" & selectedText & \"</blockqoute>
\"
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to \"http://\"
if pageURL contains \"instapaper.com\" then
set theSite to text item 3 of unescapedURL
else
set theSite to text item 2 of unescapedURL
end if
set AppleScript's text item delimiters to \"/\"
set theSite to text item 1 of theSite
set AppleScript's text item delimiters to oldDelims
set s to s & \"via <a href=\\"\" & pageURL & \"\\" target=\\"_blank\\">\" & theSite & \"</a>\"
set body to s
end if
end tell
end tell
tell application \"Google Chrome\" to close active tab of window 1
It looks like you're new here. If you want to get involved, click one of these buttons!