I am trying to set up a KM macro that will, after I have selected an email in Apple Mail, do the following: (1) copy the mail link, (2) copy the message contents (including to, from, cc, date, and subject line), (3) open a new Good Task new task window, (4) tab down to the notes section, (5) paste the mail link at top, (6) skip a couple of lines, (7) paste the message contents, then (8) then tab back up to the title field of the Good Task new task window so I can title it, select date, list, etc (happy to do this part manually).
I have found two KB forum posts with Apple Scripts that accomplish 1 and 2 (which I think is the hardest part). For #1 (copy mail link) I am using this script (David Sparks). For #2 (copy message contents) I am using this script.
I can do all the tabbing around and stuff - that's just keystrokes. What is beyond my newbie KM is how to capture the content generated by the #1 and #2 process, and get that text pasted/inserted into the GoodTask field the way I want. I assume this can be done through some use of variables, or clipboards, or....... something. Can't figure it out - can someone give me a hand?
My current macro draft (such as it is) is also attached -
Z_email snooze - bring together.kmmacros (15.0 KB)
I'd do that bit in the AppleScript, rather running two scripts to get the two parts then combining them in KM.
tell application "Mail"
set theSelection to (get selection)
if (count of theSelection) is not 1 then
display dialog "Select one, and only one, message in Mail"
return -1
end if
set theTo to ""
set theCC to ""
set theBCC to ""
set theMessage to item 1 of theSelection
--return address of item 1 of to recipients of theMessage
set theLink to "message://<" & (message id of theMessage) & ">"
repeat with eachAddress in (get to recipients of theMessage)
set theTo to ("\"" & name of eachAddress & "\" <" & address of eachAddress & ">" & linefeed)
end repeat
repeat with eachAddress in (get cc recipients of theMessage)
set theCC to ("\"" & name of eachAddress & "\" <" & address of eachAddress & ">" & linefeed)
end repeat
if theCC = "" then set theCC to linefeed
repeat with eachAddress in (get bcc recipients of theMessage)
set theBCC to ("\"" & name of eachAddress & "\" <" & address of eachAddress & ">" & linefeed)
end repeat
if theBCC = "" then set theBCC to linefeed
set theFrom to sender of theMessage
set theSubject to subject of theMessage
set dateSent to (date sent of theMessage) as rich text
set theContent to content of theMessage
end tell
return (theLink & linefeed & linefeed & "To: " & theTo & "CC: " & theCC & "BCC: " & theBCC & "From: " & theFrom & linefeed & theSubject & linefeed & dateSent & linefeed & linefeed & theContent)
If you pop that into an AppleScript action that saves its result into variable you can it later in KM:
Extract bits from email.kmactions (2.3 KB)
It does, as written, include lines for "CC" and "BCC" addresses even when there aren't any -- you could add extra logic to the script to cope but, TBH, I'd probably just use search and replace actions in KM to remove them!
If you'd prefer to process each "bit" of the email in KM then you'd end the AppleScript by setting KM variables, then refer to those individually later in the macro -- shout if you want help with that.