OmniFocus Actions Pack for Keyboard Maestro

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)

this OmniFocus Library.script does not work.

https://cl.ly/e4941f1c6ddb/download/Screen%252520Recording%2525202019-08-28%252520at%25252005.11%252520PM.mov

Thank you for the video, it clarifies what's happening.

The way the action works is:

  • It executes an AppleScript script
  • The AppleScript script gets the parameters from the Keyboard Maestro Action, in particular the Tag Name
  • The AppleScript script then uses the OmniFocusLibrary.scpt to do its job.

After checking the value that I get in the Script from Keyboard Maestro, it seems that somewhere between Keyboard Maestro and the AppleScript script, the Chinese characters are converted to something, in my case 你好 in Keyboard Maestro becomes ‰Ω†Â•Ω in my script.

AppleScript can handle Chinese characters, so it seems the problem is in the "system attribute" AppleScript function of Keyboard Maestro (I say it seems, because I have no way to be sure). This is beyond my level of expertise, only Peter, the developer of Keyboard Maestro, could confirm me if Chinese characters can be passed to AppleScript. I'm sorry about that.

However, I do have a workaround for you. The advantage of using a Library is that you can call the procedures directly from Keyboard Maestro. Use an "Execute AppleScript" action in Keyobard Maestro, and add the script below. This script will assign the 你好 tag to your first selected task. It tested it with your tag and it works.

use OmniFocusLibrary : script "OmniFocusLibrary" -- use for production
set theTask to OmniFocusLibrary's GetFirstSelectedTask()
set theResult to OmniFocusLibrary's SetTaskPrimaryTagByName(theTask, "你好")

Ok, Thank you very much for the information

a question how does the Project solve ??


is correct?

Yes, it's correct!

SetTaskProjectByName will set the name of the project.

I remembered there is an even easier solution:

use OmniFocusLibrary : script "OmniFocusLibrary" -- use for production
set theResult to OmniFocusLibrary's SetFirstSelectedTaskPrimaryTagByName("tag_name")
set theResult to OmniFocusLibrary's SetFirstSelectedTaskProjectByName("project_name")

The first line, "use..." tells the script to use the OmniFocusLibrary script library.
The second line will set the primary tag of the first selected task.
The third line will set the project of the first selected task.

There are more procedures available, for example SetFirstSelectedTaskName("name") to set the name of the task.

To know more about the procedures available, you can simply open OmniFocusLibrary.scpt with Script Editor (simply double-click on the OmniFocusLibrary.scpt file.) I tried to document my code thoroughly, so every procedure has a short description for what it does, the expected arguments and what it returns.

use OmniFocusLibrary : script "OmniFocusLibrary" -- use for production
set theResult to OmniFocusLibrary's SetFirstSelectedTaskProjectByName("重要")

Error: