Last active
January 12, 2017 20:42
-
-
Save acsr/59d047367d04564c09b3d7ab517bcf48 to your computer and use it in GitHub Desktop.
Generate a normalised MacOSX foldername from a selected outgoing item in apple mail
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
(* | |
CopyMailOutFoldername2Clipboard.applescript | |
https://gist.github.com/acsr/59d047367d04564c09b3d7ab517bcf48 | |
V 1.03 Copyright © 2009-2017 ACSR Industrialdesign – Armin Stross-Radschinski, developer@acsr.de | |
You may incorporate this code into your program(s) without | |
restriction. This ACSR sample code has been provided "AS IS" and the | |
responsibility for its operation is yours. You are not permitted to | |
redistribute this ACSR sample code as "ACSR sample code" after having | |
made changes. If you're going to redistribute the code, we require that | |
you make it clear that the code was descended from ACSR sample code, | |
but that you've made changes. | |
*) | |
(* | |
This script takes the information from a selected mail item in | |
apple mail and creates a normalized folder name suitable to | |
archive the content of an outgoing mail starting with a timestamp, | |
a directional type prefix, the name of the communication partner | |
and the subject of the selected mail. Then it copies the name | |
into the clipboard. See other script for incoming mails. | |
*) | |
(* | |
ToDo: Remove / substitute characters not suitable for folder names. | |
*) | |
(* | |
Attributes of type date | |
http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_classes.html#//apple_ref/doc/uid/TP40000983-CH1g-BBCGECID | |
*) | |
tell application "Mail" | |
set selectedMessages to selection | |
if (count of selectedMessages) is equal to 0 then | |
display alert "No e-mail selected" message "Select an e-mail bevore you invoke this applescript!" | |
else | |
set theMessage to item 1 of selectedMessages | |
set theDateTime to "Date received: " & date received of theMessage as text | |
set theSender to (extract name from sender of theMessage) as text | |
set theRecipient to (name of recipient of theMessage) as text | |
set theBetreff to subject of theMessage as text | |
set theDate to date received of theMessage | |
set theTime to (time string of theDate) as text | |
set theTime4Files to characters 1 thru 2 of theTime & "-" & characters 4 thru 5 of theTime & "-" & characters 7 thru 8 of theTime | |
set theDayTemp to (day of theDate) + 100 as string | |
set theDay to characters 2 thru 3 of theDayTemp | |
set theMonthTemp to ((month of theDate as number) + 100) as string | |
set theMonth to characters 2 thru 3 of theMonthTemp | |
set theYear to year of theDate as string | |
set theShortYear to characters 3 thru 4 of theYear | |
set theShortDate to theShortYear & theMonth & theDay | |
set theLongDate to theYear & theMonth & theDay | |
set theMailFolderName to theLongDate & "_" & theTime4Files & "_MailE_" & theSender & "_" & theBetreff | |
display dialog "Suggested foldername for storing the plain files of " & return & "the content of this e-mail in your communications folder is: " & return & return & "\"" & theMailFolderName & "\"" buttons {"to Clipboard!", "OK"} default button 2 | |
if the button returned of the result is "to Clipboard!" then | |
set the clipboard to theMailFolderName as text | |
end if | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment