Created
October 28, 2022 08:01
-
-
Save mu373/edd8985f2af352f87080f545c070ffdd to your computer and use it in GitHub Desktop.
CotEditor script to compose new mail message from selected text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
New mail message from selected text.applescript | |
Description: | |
Make a new mail message from selected text | |
Subject of the mail message can be specified by entering "subject:" in the first line (optional) | |
written by mu373 on 2022-10-28 | |
*) | |
-- | |
set fromAddress to "foobar@example.com" | |
set theSubject to "" -- optional | |
tell application "CotEditor" | |
if not (exists front document) then return | |
tell front document | |
set {loc, len} to range of selection | |
if len = 0 then return | |
set selectedText to contents of selection | |
end tell | |
end tell | |
set theContent to selectedText | |
if {selectedText starts with "subject:"} then | |
set subjectLine to item 1 of paragraphs of selectedText | |
set theSubject to replaceText(subjectLine, "subject:", "") | |
-- Remove the first line with subject: | |
set theContent to do shell script "sed -e '1d' <<< " & quoted form of selectedText | |
end if | |
tell application "Mail" | |
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true} | |
tell theMessage | |
set the sender to fromAddress | |
end tell | |
end tell | |
on replaceText(theText, serchStr, replaceStr) | |
set tmp to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to serchStr | |
set theList to every text item of theText | |
set AppleScript's text item delimiters to replaceStr | |
set theText to theList as string | |
set AppleScript's text item delimiters to tmp | |
return theText | |
end replaceText |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment