• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: saving mails...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: saving mails...


  • Subject: Re: saving mails...
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 06 Feb 2018 15:42:09 -0600

On 02/04/2018, at 23:32, Jean-Christophe Helary
<email@hidden <mailto:email@hidden>>
wrote:
> By the way, what I need to do is save a mail close to my job files so that
> when I deliver the job I can just open that mail and reply to it.  If there
> is a better way to keep a trace of that mail that does not imply saving it
> physically, I'm fine too :)


Hey Jean-Christophe,

You should have mentioned this to start with...  😎

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2014/07/30 17:32
# dMod: 2018/02/06 15:10
# Appl: Mail
# Task: Place URL of selected message into the Clipboard.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail
----------------------------------------------------------------

tell application "Mail"
        set _sel to get selection
        set _links to {}

        repeat with _msg in _sel
                set _messageURL to "message://< <message://<>" & _msg's
message id & ">"
                set end of _links to _messageURL
        end repeat

        set AppleScript's text item delimiters to return

        set the clipboard to (_links as string)

end tell

----------------------------------------------------------------

This will give you a clickable link that works in a number of applications, and
it can be transformed into a Rich-Text link with a little more effort.


If you want a clickable file/link in the Finder then you'll need to do
something like this:

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2014/07/30 17:32
# dMod: 2018/02/06 15:10
# Appl: Mail
# Task: Make a clickable reference to the selected Mail message in the Finder
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @Make, @Clickable, @Reference, @Selected,
@Message, @Finder, @File
----------------------------------------------------------------

set xmlTemplate to text 2 thru -1 of "
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\"
\"http://www.apple.com/DTDs/PropertyList-1.0.dtd
<http://www.apple.com/DTDs/PropertyList-1.0.dtd>\">
<plist version=\"1.0\">
<dict>
    <key>URL</key>
    <string>%Message_URL_Placeholder%</string>
</dict>
</plist>
"

tell application "Mail"
    set selectedMessagesList to get selection

    if length of selectedMessagesList = 1 then
        set selectedMessage to item 1 of selectedMessagesList
    else
        error "Please select 1 message!"
    end if

    set messageURL to "message://< <message://<>" & selectedMessage's
message id & ">"

end tell

set xmlTemplate to findReplTIDS("%Message_URL_Placeholder%", messageURL,
xmlTemplate)

set messageLinkPath to (path to downloads folder as text) &
"test_Mail_Message_Link.inetloc"

writeUTF8(xmlTemplate, messageLinkPath) of me

----------------------------------------------------------------
--» HANDLERS
----------------------------------------------------------------
on findReplTIDS(_find, _replace, _string)
    set oldTIDS to AppleScript's text item delimiters
    set AppleScript's text item delimiters to _find
    set _string to text items of _string
    set AppleScript's text item delimiters to _replace
    set _string to _string as text
end findReplTIDS
----------------------------------------------------------------
on writeUTF8(_text, targetFilePath)
    try
        if targetFilePath starts with "~/" then
            set targetFilePath to POSIX path of (path to home folder as text) &
text 3 thru -1 of targetFilePath
        end if
        set fRef to open for access targetFilePath with write permission
        set eof of fRef to 0
        write _text to fRef as «class utf8»
        close access fRef
    on error e number n
        try
            close access fRef
        on error e number n
            error "Error in writeUTF8() handler of library: gen.lib" & return &
return & e
        end try
    end try
end writeUTF8
----------------------------------------------------------------

You can change how it creates the file name and where it places the file to
suit yourself.


>> Finding it with Spotlight is slow in computer terms but reasonably
>> acceptable in human terms.
>
> Finding the way to accomplish that is pretty slow and not really acceptable
> in human terms though.

I'm not quite sure what you mean by that.

Pretty slow in this case is between 0.2 and 1 second, and while I vehemently
dislike it when a 21st Century computer makes me wait for anything
(unreasonably) – that's still not too bad.

--
Take Care,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: saving mails...
      • From: Jean-Christophe Helary <email@hidden>
References: 
 >saving mails... (From: Jean-Christophe Helary <email@hidden>)
 >Re: saving mails... (From: Christopher Stone <email@hidden>)
 >Re: saving mails... (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: text selection in general...
  • Next by Date: Re: text selection in general...
  • Previous by thread: Re: saving mails...
  • Next by thread: Re: saving mails...
  • Index(es):
    • Date
    • Thread