Forked from henryroe/Save mail attachments with pre-pended YYYY-MM-DD_.kmmacros
Created
October 10, 2019 12:53
-
-
Save mals14/dfb6b5d77818d78fe33c83266657279c to your computer and use it in GitHub Desktop.
Keyboard Maestro macro to take Mail.app attachments, pre-pend YYYY-MM-DD_..., and save to user-selected dir
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
<?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"> | |
<plist version="1.0"> | |
<array> | |
<dict> | |
<key>Activate</key> | |
<string>Normal</string> | |
<key>IsActive</key> | |
<true/> | |
<key>Macros</key> | |
<array> | |
<dict> | |
<key>Actions</key> | |
<array> | |
<dict> | |
<key>DisplayKind</key> | |
<string>Variable</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>ExecuteAppleScript</string> | |
<key>Path</key> | |
<string></string> | |
<key>Text</key> | |
<string>tell application "Default Folder X Helper" | |
activate | |
the POSIX path of (choose folder) | |
end tell</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
<key>TrimResults</key> | |
<true/> | |
<key>TrimResultsNew</key> | |
<true/> | |
<key>UseText</key> | |
<true/> | |
<key>Variable</key> | |
<string>curSavePath</string> | |
</dict> | |
<dict> | |
<key>AllWindows</key> | |
<false/> | |
<key>AlreadyActivatedActionType</key> | |
<string>Normal</string> | |
<key>Application</key> | |
<dict> | |
<key>BundleIdentifier</key> | |
<string>com.apple.mail</string> | |
<key>Name</key> | |
<string>Mail</string> | |
<key>NewFile</key> | |
<string>/Applications/Mail.app</string> | |
</dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>ActivateApplication</string> | |
<key>ReopenWindows</key> | |
<false/> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>DisplayKind</key> | |
<string>Variable</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>ExecuteAppleScript</string> | |
<key>Path</key> | |
<string></string> | |
<key>Text</key> | |
<string>tell application "Mail" | |
set curMessage to selection | |
set curMessageDate to date received of item 1 of curMessage | |
(rich text -4 thru -1 of ("0000" & (year of curMessageDate))) & "-" & ¬ | |
(rich text -2 thru -1 of ("00" & ((month of curMessageDate) as integer))) & "-" & ¬ | |
(rich text -2 thru -1 of ("00" & (day of curMessageDate))) | |
end tell</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
<key>TrimResults</key> | |
<true/> | |
<key>TrimResultsNew</key> | |
<true/> | |
<key>UseText</key> | |
<true/> | |
<key>Variable</key> | |
<string>receivedDate</string> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>SelectMenuItem</string> | |
<key>Menu</key> | |
<array> | |
<string>File</string> | |
<string>Save Attachments…</string> | |
</array> | |
<key>TargetApplication</key> | |
<dict> | |
<key>BundleIdentifier</key> | |
<string>com.apple.mail</string> | |
<key>Name</key> | |
<string>Mail</string> | |
<key>NewFile</key> | |
<string>/Applications/Mail.app</string> | |
</dict> | |
<key>TargetingType</key> | |
<string>Specific</string> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Pause</string> | |
<key>Time</key> | |
<string>3.0</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>KeyCode</key> | |
<integer>2</integer> | |
<key>MacroActionType</key> | |
<string>SimulateKeystroke</string> | |
<key>Modifiers</key> | |
<integer>768</integer> | |
<key>ReleaseAll</key> | |
<false/> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Pause</string> | |
<key>Time</key> | |
<string>1.0</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>KeyCode</key> | |
<integer>45</integer> | |
<key>MacroActionType</key> | |
<string>SimulateKeystroke</string> | |
<key>Modifiers</key> | |
<integer>256</integer> | |
<key>ReleaseAll</key> | |
<false/> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Pause</string> | |
<key>Time</key> | |
<string>1.0</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>SetVariableToText</string> | |
<key>Text</key> | |
<string>D57D6B3A-85B0-4D5C-8726-10DB2F7FE14C_%ICUDateTime%yyyy-MM-dd_HH-mm-ss%</string> | |
<key>Variable</key> | |
<string>curTempDir</string> | |
</dict> | |
<dict> | |
<key>Action</key> | |
<string>ByTyping</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>InsertText</string> | |
<key>Paste</key> | |
<false/> | |
<key>Text</key> | |
<string>%Variable%curTempDir%</string> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>KeyCode</key> | |
<integer>36</integer> | |
<key>MacroActionType</key> | |
<string>SimulateKeystroke</string> | |
<key>Modifiers</key> | |
<integer>0</integer> | |
<key>ReleaseAll</key> | |
<false/> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Pause</string> | |
<key>Time</key> | |
<string>2.0</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>ButtonName</key> | |
<string>Save</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>PressButton</string> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Pause</string> | |
<key>Time</key> | |
<string>3.0</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>Conditions</key> | |
<dict> | |
<key>ConditionList</key> | |
<array> | |
<dict> | |
<key>ConditionType</key> | |
<string>Script</string> | |
<key>Path</key> | |
<string></string> | |
<key>ScriptConditionSourceType</key> | |
<string>ShellScriptText</string> | |
<key>ScriptConditionType</key> | |
<string>ReturnsSuccess</string> | |
<key>ScriptResult</key> | |
<string></string> | |
<key>ScriptTerminationStatus</key> | |
<integer>1</integer> | |
<key>ScriptText</key> | |
<string>if test "$(ls "/Users/hroe/Desktop/"$KMVAR_curTempDir)"; then | |
exit 0 | |
else | |
exit 1 | |
fi | |
</string> | |
</dict> | |
</array> | |
<key>ConditionListMatch</key> | |
<string>All</string> | |
</dict> | |
<key>ElseActions</key> | |
<array> | |
<dict> | |
<key>DisplayKind</key> | |
<string>None</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>ExecuteAppleScript</string> | |
<key>Path</key> | |
<string></string> | |
<key>Text</key> | |
<string>tell application "System Events" | |
activate | |
display dialog "No files appear to have been saved from Mail." | |
end tell | |
</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
<key>TrimResults</key> | |
<true/> | |
<key>TrimResultsNew</key> | |
<true/> | |
<key>UseText</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>Application</key> | |
<dict> | |
<key>BundleIdentifier</key> | |
<string>com.apple.finder</string> | |
<key>Name</key> | |
<string>Finder</string> | |
<key>NewFile</key> | |
<string>/System/Library/CoreServices/Finder.app</string> | |
</dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDefaultApplication</key> | |
<false/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Open1File</string> | |
<key>Path</key> | |
<string>/Users/hroe/Desktop/%Variable%curTempDir%</string> | |
</dict> | |
</array> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>IfThenElse</string> | |
<key>ThenActions</key> | |
<array> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>SetVariableToText</string> | |
<key>Text</key> | |
<string></string> | |
<key>Variable</key> | |
<string>outputString</string> | |
</dict> | |
<dict> | |
<key>Actions</key> | |
<array> | |
<dict> | |
<key>DisplayKind</key> | |
<string>Variable</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>ExecuteShellScript</string> | |
<key>Path</key> | |
<string></string> | |
<key>Text</key> | |
<string>basename "$KMVAR_Path"</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
<key>TrimResults</key> | |
<true/> | |
<key>TrimResultsNew</key> | |
<true/> | |
<key>UseText</key> | |
<true/> | |
<key>Variable</key> | |
<string>basename</string> | |
</dict> | |
<dict> | |
<key>DisplayKind</key> | |
<string>Variable</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>ExecuteShellScript</string> | |
<key>Path</key> | |
<string></string> | |
<key>Text</key> | |
<string>dirname "$KMVAR_Path"</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
<key>TrimResults</key> | |
<true/> | |
<key>TrimResultsNew</key> | |
<true/> | |
<key>UseText</key> | |
<true/> | |
<key>Variable</key> | |
<string>dirname</string> | |
</dict> | |
<dict> | |
<key>Destination</key> | |
<string>%Variable%dirname%/%Variable%receivedDate%_%Variable%basename%</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>File</string> | |
<key>Operation</key> | |
<string>Move</string> | |
<key>Source</key> | |
<string>%Variable%Path%</string> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Pause</string> | |
<key>Time</key> | |
<string>1.0</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>Destination</key> | |
<string>%Variable%curSavePath%%Variable%receivedDate%_%Variable%basename%</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>File</string> | |
<key>Operation</key> | |
<string>Move</string> | |
<key>Source</key> | |
<string>%Variable%dirname%/%Variable%receivedDate%_%Variable%basename%</string> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>SetVariableToText</string> | |
<key>Text</key> | |
<string>%Variable%outputString% | |
%Variable%curSavePath%%Variable%receivedDate%_%Variable%basename%</string> | |
<key>Variable</key> | |
<string>outputString</string> | |
</dict> | |
</array> | |
<key>Collections</key> | |
<dict> | |
<key>CollectionList</key> | |
<array> | |
<dict> | |
<key>CollectionType</key> | |
<string>Files</string> | |
<key>IncludeInvisibles</key> | |
<false/> | |
<key>Path</key> | |
<string>/Users/hroe/Desktop/%Variable%curTempDir%</string> | |
<key>Recursive</key> | |
<false/> | |
</dict> | |
</array> | |
</dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>For</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
<key>Variable</key> | |
<string>Path</string> | |
</dict> | |
<dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Pause</string> | |
<key>Time</key> | |
<string>2.0</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>Conditions</key> | |
<dict> | |
<key>ConditionList</key> | |
<array> | |
<dict> | |
<key>ConditionType</key> | |
<string>Script</string> | |
<key>Path</key> | |
<string></string> | |
<key>ScriptConditionSourceType</key> | |
<string>ShellScriptText</string> | |
<key>ScriptConditionType</key> | |
<string>ReturnsSuccess</string> | |
<key>ScriptResult</key> | |
<string></string> | |
<key>ScriptTerminationStatus</key> | |
<integer>1</integer> | |
<key>ScriptText</key> | |
<string>if test "$(ls "/Users/hroe/Desktop/"$KMVAR_curTempDir)"; then | |
exit 0 | |
else | |
exit 1 | |
fi | |
</string> | |
</dict> | |
</array> | |
<key>ConditionListMatch</key> | |
<string>All</string> | |
</dict> | |
<key>ElseActions</key> | |
<array> | |
<dict> | |
<key>DisplayKind</key> | |
<string>None</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>ExecuteAppleScript</string> | |
<key>Path</key> | |
<string></string> | |
<key>Text</key> | |
<string>tell application "Keyboard Maestro Engine" | |
set kmVarOutputString to make variable with properties {name:"outputString"} | |
set outputString to value of kmVarOutputString | |
end tell | |
tell application "System Events" | |
activate | |
display dialog outputString | |
end tell | |
</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
<key>TrimResults</key> | |
<true/> | |
<key>TrimResultsNew</key> | |
<true/> | |
<key>UseText</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>Application</key> | |
<dict> | |
<key>BundleIdentifier</key> | |
<string>com.apple.finder</string> | |
<key>Name</key> | |
<string>Finder</string> | |
<key>NewFile</key> | |
<string>/System/Library/CoreServices/Finder.app</string> | |
</dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDefaultApplication</key> | |
<false/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Open1File</string> | |
<key>Path</key> | |
<string>%Variable%curSavePath%</string> | |
</dict> | |
<dict> | |
<key>Destination</key> | |
<string></string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>File</string> | |
<key>Operation</key> | |
<string>RecursiveDelete</string> | |
<key>Source</key> | |
<string>/Users/hroe/Desktop/%Variable%curTempDir%</string> | |
</dict> | |
</array> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>IfThenElse</string> | |
<key>ThenActions</key> | |
<array> | |
<dict> | |
<key>DisplayKind</key> | |
<string>None</string> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>ExecuteAppleScript</string> | |
<key>Path</key> | |
<string></string> | |
<key>Text</key> | |
<string>tell application "System Events" | |
activate | |
display dialog "Failed to move one or more files; Will open folder once you dismiss this dialog." | |
end tell | |
</string> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
<key>TrimResults</key> | |
<true/> | |
<key>TrimResultsNew</key> | |
<true/> | |
<key>UseText</key> | |
<true/> | |
</dict> | |
<dict> | |
<key>Application</key> | |
<dict> | |
<key>BundleIdentifier</key> | |
<string>com.apple.finder</string> | |
<key>Name</key> | |
<string>Finder</string> | |
<key>NewFile</key> | |
<string>/System/Library/CoreServices/Finder.app</string> | |
</dict> | |
<key>IsActive</key> | |
<true/> | |
<key>IsDefaultApplication</key> | |
<false/> | |
<key>IsDisclosed</key> | |
<true/> | |
<key>MacroActionType</key> | |
<string>Open1File</string> | |
<key>Path</key> | |
<string>/Users/hroe/Desktop/%Variable%curTempDir%</string> | |
</dict> | |
</array> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
</array> | |
<key>TimeOutAbortsMacro</key> | |
<true/> | |
</dict> | |
</array> | |
<key>IsActive</key> | |
<true/> | |
<key>ModificationDate</key> | |
<real>445743866.02222902</real> | |
<key>Name</key> | |
<string>Save mail attachments with pre-pended YYYY-MM-DD_</string> | |
<key>Triggers</key> | |
<array/> | |
<key>UID</key> | |
<string>D57D6B3A-85B0-4D5C-8726-10DB2F7FE14C</string> | |
</dict> | |
</array> | |
<key>Name</key> | |
<string>Mail Macro Group</string> | |
<key>Targeting</key> | |
<dict> | |
<key>Targeting</key> | |
<string>Included</string> | |
<key>TargetingApps</key> | |
<array> | |
<dict> | |
<key>BundleIdentifier</key> | |
<string>com.apple.mail</string> | |
<key>Name</key> | |
<string>Mail</string> | |
<key>NewFile</key> | |
<string>/Applications/Mail.app</string> | |
</dict> | |
</array> | |
</dict> | |
<key>UID</key> | |
<string>D697E22E-20AE-4799-91D7-DC851E1F4F19</string> | |
</dict> | |
</array> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment