OmniFocus Actions Pack for Keyboard Maestro

The elements are in the right location. Now:

  • Create a new macro in Keyboard Maestro
  • Click on Add Action
  • You should be able to find the actions in Keyboard Maestro in the "Third Party Plugin" category (see screenshot). Note: you will see more third party actions in my screenshot, the action pack only includes the OmniFocus actions.

I have also added an OmniFocus Palette Demo Library in my original post to help you get started (see original post).

I must be doing something wrong, as I do not have the 3rd party smart folder like you do....

05%20PM

You're showing the list of existing macros. What you need to do is:

  • Create a new macro: click on the "+" button under the "Macros" column.

image

  • Give a name to your new macro.
  • Now, click on the "+" button under the new macro, or on the "New Action" button.

In the actions list that will pop-up on the left of your new macro, you should have the Third Party plugin category. You may need to scroll up to see it.

1 Like

THANK YOU! I am new to KM and this helps so much!!!!

1 Like

Kornichon,

Many thanks for your pack.
I have been researching different todo type applications that I can interact with Mail.
Being able to use message IDs and scripting was important to ease the interactions between the 2 programs.
Your pack gave me the incredible start I needed to move forward.

You have some other macros shown above regarding mail.
Would you be able to share them also?
Anything to help bridge the 2 apps together would be great.

Thanks,
Brett

[Updated to include 2 actions to get IDs and URLs of selected messages, also updated so that list items are separated with new lines instead of commas, so that it is easier to process list items in Keyboard Maestro.]

Hi Brett, sorry for the slow reply, I was on holiday, without a computer.

Here is the Mail Actions Pack, it is similar to the OmniFocus Actions Pack: you have to:

  • Uncompress and copy the MailLibrary.scpt in ~/Library/Script Libraries/
  • Uncompress and copy the Mail Actions Pack actions to ~/Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions/

This pack provides five actions:

  • Mail Get IDs of Selected Messages
  • Mail Get URLs of Selected Messages
  • Mail Forward Message with ID
  • Mail Open Message with ID
  • Mail Reply To Message with ID (with Reply to All option)

I have included four macro examples in the OmniFocus Palette Mail Macros.kmlibrary Library.

You can get the unique ID of a message with AppleScript. Or you can use the provided Keyboard Maestro Action "Mail Get IDs of Selected Messages". To get the URL of the currently selected messages, simply use the Keyboard Maestro Action "Mail Get URLs of Selected Messages".

A bit of explanation:
The Mail message ID is extracted from a Mail message URL with the following format: message://%3cmessageID%3e for example message://%3cwT7bskxLPA@ismtpd0027%3e - the message://%3c and %3e tokens are used to find the message ID. This means that for these macros to work, your OmniFocus task should have a valid message://... URL in its notes (see screenshot below). It doesn't have to be the first line in the note.

Screenshot%202019-08-18%20at%2009h03m18s

See attached script "rule → omnifocus.sendto.scpt" as an example. This is the script that I use to send every unread Mail message to OmniFocus Inbox (I trigger it with Keyboard Maestro when OmniFocus comes to the front). It is unlikely to work as is, you'll probably need to adapt it to your specific environment. See screenshot below for the Keyboard Maestro script that I use to trigger it.

I hope this helps.

OmniFocus Palette Mail Macros.kmlibrary (78.0 KB)

MailLibrary.scpt.zip (478.2 KB)
Mail Actions Pack for Keyboard Maestro.zip (2.3 MB)

1 Like

Hi,
Am I correct in thinking that the Mail actions only work if the original mail is in the INBOX mailbox? I have a weird setup, involving (among other things) Sanebox, and some of my mails are stored in a SaneLater box. The KM Actions you offer as demo (for mail) don't seem to find the emails even though there is a message:// url in the notes (and it opens the proper mail if I click on it ...)
Merci!

Can you let me know which action exactly doesn't seem to work as intended? Can you also provide me with an example of the message:// url you're using? You can remove part of the ID if you're concerned with confidentiality, but please leave the beginning and end of the URL so I can check if it's not a url format problem, in particular I need to check that there are "%3c" and "%3e" at the beginning and end of your message ID.

Below is a macro example I use to reply to a mail from OmniFocus.

  • I select the task in OmniFocus containing the Mail message URL in its notes.
  • I trigger the Macro from a Keyboard Maestro palette in OmniFocus (see below). Note that the macro should be triggered with OmniFocus in the foreground, not Apple Mail.
  • It should create a reply message to the original message.
  • Note the trick I use to make sure that the reply window is brought to the front and is not hidden by the main Mail window.

Screenshot%202019-08-18%20at%2015h53m24s

Thanks!
Here's the message id: message:<1f807b8d-30cc-4b7b-9fea-fbb8d6131a6d%40Spark>

I think it's well formed. I used the Reply To macro you've set up in the examples.
I'm attaching the error message.

There were two problems (I knew the Mail Actions Pack was not really ready for wider use, this is why I didn't post it initially):

  1. I hard coded "Inbox" in the code to find the message. I did it originally because Mail's AppleScript performance is disastrous, and restricting the search to some mailboxes / accounts helps. This should be corrected in this new version, you can now specify an account name and mailbox name to restrict the search, but you don't have to (in that case the script will search every account and every mailbox until it finds the message with the matching message id, be warned that it may take a very long time, there is another method, open location, which is faster, but unfortunately doesn't allow me to do exactly what I want with replies and forwards).
  2. There is more than one valid format for message urls (crazy, I know). message://%3c...%3e, message:%3c...%3e, message://<...> and message:<...> are all valid formats. I only coded the first one (message://%3c...%3e). I added more parsing delimiters, and the other formats should be recognized (I didn't test them all!!!)

To make it work, you will need to:

  • update to V2 of OmniFocusLibrary.scpt and OmniFocus Actions Pack (see first post update)
  • update to this version of MailLibrary.scpt and Mail Actions Pack

I hope the move to the new versions goes smoothly, sometimes AppleScript keeps outdated versions of the library procedures stored in the compiled version of the scripts.

MailLibrary.scpt.zip (480.2 KB)
Mail Actions Pack for Keyboard Maestro.zip (2.3 MB)

Don't forget to stop and relaunch both the Keyboard Maestro Engine and Editor. If you have the new version, you should see the new fields Account Name and Mailbox Name in some Mail actions, and the field Task ID in OmniFocus actions:

kornichon,
Thanks for posting.
I did some of my own mail scripting to do some of what you posted, but still helpful to review what you posted to move me along.
Your scripts helped me to understand the palettes better and how to implement them.

Many thanks,
brettd0g

@kornichon,

I can't get it to work, either.

Is it perhaps different for KM 9?

I have created:

~/Library/Script Libraries/
~/Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions/

and copied the unzipped downloads there:

I then killed the Engine, and Editor and relaunched the latter:

Any help gratefully received :slight_smile:

TIA!

Hi Mark, from what i see everything seems to be in the right location. If you already did quit and relaunch Keyboard Maestro, I don't see any reason why it doesn't work (it should work in Keyboard Maestro 9 too, I just tested it).

Something you can do to help me find the source of the problem is try to install another Action from the forum. If it works, then there is something wrong with my actions. If the other action doesn't work either, then we should double check your setup.

I implemented this yesterday as described, and it worked flawlessly, so it is probably a local issue?

Thanks so much for your reply!

I really appreciate your help.

I went through this process, which you describe so clearly several times. No joy.

So I searched for - and read - this page.

After I did it this way:

To install an action, download it and drop the .zip file on the Keyboard Maestro dock icon. To update an existing action, you must remove the old version from the Keyboard Maestro Actions folder first.

It worked.

Although doing that (zip onto the dock icon) did duplicate the subfolder. So I removed it.

And I correct in thinking that you really do need to create:

~/Library/Script Libraries

and put the OmniFocusLibrary.scpt file there; and not in:

~/Library/Application\ Scripts/com.omnigroup.OmniFocus3

?

If so, I think I’m all set, thank you.

But I do hope this will also be a small help, perhaps, to you for seeing why the method you designed it for doesn’t seem to work in all cases. At least in my case :slight_smile:

If I can look at anything else in that regard, please do say.

And - again - thanks very much!

Thanks, I've got it working now… I think!

It seems as though you do have to drop the zip onto the KM dock icon. Moving its contents into a manually-created sub-directory still always fails - at least in my case.

(I did stop both Engine and App.)

Thanks again, both!

Thank you for the feedback. I will try to update the installation instructions to include your advice. However, if drag-and-dropping the .zip created a duplicate folder, it means that the other folder probably contains an incorrect, invisible character (maybe a space at the end, or something else) - macOS does not allow the creation of two folders with the exact same names in the same location, so there must be a difference.

And you're right, the OmniFocusLibrary.scpt should be in ~/Library/Script Libraries:

  • Individual scripts interacting with OmniFocus should be in ~/Library/Application Scripts/com.omnigroup.OmniFocus3
  • Script libraries (libraries that provide common functions and procedures to other scripts) should always be in ~/Library/Script Libraries

@kornichon,

Thanks so much for your help here :slight_smile:

I’m a little puzzled because between this post and this post of yours (leaving the Third Party step out of things), cable0 seems to have fixed it in the way you intended, and not in the way assumed by dropping zips.

I take your point 100% about the impossibility of my having two apparently identically-named folders, Yes!

I did try it three or four times. the very first one I was copying and pasting 'Keyboard Maestro Actions’ from your OP.

Maybe the spaces weren’t consistently/correctly escaped?

Your confirmation on script libraries appreciated.

And thanks again for this very useful set of routines!

Omnifocus Set Project Name to 你好
Omnifocus Set Primary Tag of First Selected Task 你好

Project name is Chinese, Omnifocus Set Project Name and Omnifocus Set Primary Tag Does not work
how can i solve it?

Hello,

Can you try this version of OmniFocusLibrary.scpt ? I left a bug in the new version of the Library (as I warned, this new version of the library hasn't been time tested yet). The bug had nothing to do with the character set used, so it should work with Chinese characters.

OmniFocusLibrary.scpt.zip (482.1 KB)