Hi,
I’ve got a script that I use for sending instructions to a customer, it works great but I’ve recently found the need to add some text, that is, their address from the recipients original order. I found a script that was designed to extract text from an email and make a calendar entry but I can’t fudge it to work with my script. I’m using Quicksilver to operate the script, but Quicksilver won’t run the copy part of the script so my clipboard is always blank or worse, contains someone else’s address. The text/address I want to get either onto the clipboard or into a variable is between.
“delivery address”
and
“Instructions to merchant:”
Here’s my script.
--This top bit works okay with AppleScript Editor but not with Quicksilver. Obviously I have to select the text manually for each Mail message which is like buying a dog and barking myself.
tell application "Mail" to activate
tell application "System Events"
tell process "Mail"
keystroke "c" using command down
end tell
end tell
tell application "Mail"
set thesenders to {}
set thesenderstext to ""
set youraddress to the clipboard
set theMessages to the selection
repeat with eachMessage in the theMessages
repeat with i from 1 to the number of items in eachMessage
set theAccount to "me@mydomain.com"
set theSender to (extract address from (the reply to of (item i of eachMessage)))
if thesenders does not contain theSender then
set thesenders to {theSender}
end if
set replyName to (extract name from (the sender of (item i of eachMessage)))
set titleCaseString to (do shell script "/bin/echo" & space & quoted form of replyName & space & "| /usr/bin/perl -p -e 's/(\\w+)/\\u\\L$1/g;'") as Unicode text
set firstName to word 1 of titleCaseString
end repeat
set AppleScript's text item delimiters to ", "
set thesenderstext to thesenders as rich text
set AppleScript's text item delimiters to ""
set newMessage to make new outgoing message
set theSubject to "Instructions"
set theContent to "Dear " & firstName & ",
Thanks so much for your order. Your item is being sent to:
" & youraddress & "
...
Kind Regards
Jim
"
set newMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
set theAttachment1 to POSIX file "/Users/Jim/qrcode.13177607.png"
set theAttachment2 to POSIX file "/Users/Jim/qrcode.13177658.png"
set theAttachment3 to POSIX file "/Users/Jim/qrcode.13177665.png"
tell newMessage
set visible to true
make new to recipient with properties {address:thesenderstext}
--make new bcc recipient at end with properties {address:theBccRecipient}
make new attachment with properties {file name:theAttachment1} at after the last paragraph
make new attachment with properties {file name:theAttachment2} at after the last paragraph
make new attachment with properties {file name:theAttachment3} at after the last paragraph
-- send
end tell
tell application "Mail"
set a to selection
repeat with s in a
set flag index of s to -1 as integer
end repeat
set theSelection to the selection
repeat with theMessage in the theSelection
move theMessage to mailbox "orders" -- of account theAccount
activate
end repeat
end tell
end repeat
set read status of every message of mailbox "orders" to true
end tell
Thanks
Jim
AppleScript: Version 2.5.1 (138.1)
Browser: Safari 537.77.4
Operating System: Mac OS X (10.8)