Created
February 23, 2016 14:00
-
-
Save shibaku/126bcfe33027e7fc4958 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Gets dates I'll use to rename files | |
set thisYear to do shell script "date '+%Y'" | |
set thisMonth to do shell script "date '+%m'" | |
set lastMonth to do shell script "date -v -1m '+%m'" | |
set thisDay to do shell script "date '+%d'" | |
(If I'm processing reports at the end of the month, use current month for file name. If not, use last month. *) | |
if thisDay > 20 then | |
set myDate to thisYear & "-" & thisMonth | |
else | |
set myDate to thisYear & "-" & lastMonth | |
end if | |
# Save attachments from current mail message | |
tell application "Mail" | |
set selectedMessages to selection | |
set destinationFolder to choose folder with prompt "Pick a Destination" | |
repeat with currentMessage in selectedMessages | |
repeat 1 times | |
set msgSenderFull to extract name from sender of currentMessage | |
set msgSender to word 2 of msgSenderFull | |
set msgAttachments to mail attachments of currentMessage | |
if (msgAttachments is equal to {}) then | |
exit repeat | |
end if | |
tell application "Finder" | |
if not (exists folder msgSender of destinationFolder) then | |
set senderFolder to (make new folder at destinationFolder with properties {name:msgSender}) | |
else | |
set senderFolder to (folder msgSender of destinationFolder) | |
end if | |
end tell | |
repeat with currentAttachment in msgAttachments | |
if (downloaded of currentAttachment is true) then | |
set currentAttachmentPath to (senderFolder as string) & (name of currentAttachment) | |
save currentAttachment in currentAttachmentPath | |
end if | |
end repeat | |
end repeat | |
end repeat | |
end tell | |
on rename_file(currentAttachment) | |
# check if filename is pdf | |
# check if filename is excel | |
# check if expenses are credit card | |
# check if expenses are out of pocket | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment