I am a couple days into a trial of KM. So far mostly failures but with a few glimmers of hope. I got the applescript that Sparky posted that retrieves sender, date, subject etc info and concatenates into a filename for a PDF version working. Properly named PDFs were being created so I moved on to adding another script to the macro that would move the emails to other folders. Things started going down hill in a hurry this morning. The macro started throwing errors and I started simplifying back trying to get to a point where any part of the script worked. It went from throwing errors to losing all the color in the window. Since the standalone applescript still builds the file name properly, I am wondering if the free trial expired. I am running Big Sur on MBP 2018.
The script that runs as a standalone script but fails inside KM:
--clear variables
set msgSourceDay to {}
set msgSender to {}
set msgRecipient to {}
set msgSubject to {}
tell application "Mail" to if running then
repeat with tMsg in (get selection)
--get information from Mail about the message
set msgSourceDay to the (date received of tMsg)
set msgSender to the (extract name from sender of tMsg)
set msgRecipient to the (name of first to recipient of tMsg)
set msgSubject to the (subject of tMsg)
end repeat
end if
--Set message date and time in ISO Format
set msgMonth to rich text -1 thru -2 of ("0" & (month of msgSourceDay as number))
set msgDay to rich text -1 thru -2 of ("0" & (day of msgSourceDay as number))
set msgYear to year of msgSourceDay
--Set message Name text string
set newName to "Emails " & msgYear & "-" & msgMonth & "-" & msgDay & "- Sender: " & msgSender & "- Recipient:" & msgRecipient & "-" & msgSubject
display dialog newName
--Set Keyboard Maestro Variable
tell application "Keyboard Maestro Engine"
setvariable "New Name" to newName
end tell
It is always good to upload the actual Keyboard Maestro Macro you are having problems with to the Forum. Much quicker for others to test and see if they can find why it doesn't work. Here's how to do that:
As Keyboard Maestro is designed as a modular system with Actions simply added one after the other and as many native Keyboard Maestro Actions can do similar things to AppleScript (with the advantage that they are already bug free and are easy to customise) you might find that some of your script can be replaced with Keyboard Maestro Actions. Just a thought.
Clearly you were not able to upload your macro, and included a lot of other text from a forum page that was unrelated to your upload. So I removed that text.
Also, you did NOT upload your Macro, you uploaded only one Action.
Before you start the upload process, you must first select the Macro in the Macro panel/column.
If you try to run before you can walk, then it is likely to lead to a lot of frustration, in the same way if you opened Microsoft Word for the first time and tried to start writing your dissertation, you would find it very frustrating figuring out how to set up style sheets and bibliographies and such.
Always compose AppleScripts in the Apple Script Editor or better yet Script Debugger.
(The demo reverts to its freeware “Lite” version after a 30 day evaluation period, but is still enormously superior to the Script Editor).
Once you have a script compiling and working in a proper development environment, you can paste it into your Keyboard Maestro macro.
Mail has a bad habit under certain circumstances of turning the noun “text” into “rich text”, and this will usually fail to compile.
This compiles and works in Apple Mail on Mojave:
tell application "Mail" to if running then
repeat with tMsg in (get selection)
--get information from Mail about the message
set msgSourceDay to the (date received of tMsg)
set msgSender to the (extract name from sender of tMsg)
set msgRecipient to the (name of first to recipient of tMsg)
set msgSubject to the (subject of tMsg)
--Replace Teresa's name with TC
if msgSender is "Pamela Parks" then set msgSender to "PP"
if msgRecipient is "Pamela Parks" then set msgRecipient to "PP"
end repeat
end if
--Set message date and time in ISO Format
set msgMonth to text -1 thru -2 of ("0" & (month of msgSourceDay as number))
set msgDay to text -1 thru -2 of ("0" & (day of msgSourceDay as number))
set msgYear to year of msgSourceDay
--Set message Name text string
set newName to "Emails " & msgYear & "-" & msgMonth & "-" & msgDay & "- Sender: " & msgSender & "- Recipient:" & msgRecipient & "-" & msgSubject
--Set Keyboard Maestro Variable
tell application "Keyboard Maestro Engine"
setvariable "New Name" to newName
end tell
I don't know why you're using a repeat loop, when you're not accumulating anything – only the last selected message will give you any data...
Hi Pam, welcome to Keyboard Maestro (KM) and its Forum.
KM is one of the best Mac automation tools available, its Forum is one of the best and friendliest forums on the Internet. Whenever you reach a tough stumbling block trying to use KM, please feel free to post your question/problem here for help.
If you get any errors, or unexpected results, post a screenshot of those.
Post the expected result of your macro
Provide the versions of KM and macOS you are running.
As @peternlewis mentioned above, you may be trying to write a complicated macro before you are ready to do so. One good approach is to write separate macros for each part of your workflow, so that you can easily test and confirm the results before moving on to the next step.
Plenty of good advice in here that probably bares repeating even though it may not have much to do with my situation.
Early on I got the applescript portions of my macro working as stand alone scripts.... and indeed these scripts were not my first. They followed working through several dozen scripts from the now dated but useful texts by Sanderson and Rosenthal. And the KM macro I attempted to post was not the first attempted.... I got through several examples and tutorials before modifying Sparky's Macro that makes PDF of Mail messages. I did get his macro to work briefly and was in the process of tweaking it for my situation when things started failing. No amount of reverting to earlier versions would get his Macro working again. The major impediment in me making further progress is that at this point KM is not functioning at all. My guess is that the trial period ended. Less than a week seems short but I don't recall seeing what the trial limit was. The effort has certainly not been wasted as I was able to finish up the applescripts and they do the job. Not nearly as slick as could be done with KM but functional. At this point my best way forward may be to either procure another trial period or just wait and see what the Shortcuts application will offer later this year.