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
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!
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.
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, "你好")
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.
I think I've found the reason: is your project empty? (no tasks)? There is a problem with the OmniFocus AppleScript command that moves tasks to projects when the project is empty. I'm sorry, I could not find a workaround for this problem. In the meantime, the best thing to do is to ensure that the project already has at least one task.
If it helps, I was having exactly the same problem. As you say, it went away after creating a placeholder task in the project.
This is a great set of actions by the way. I found them a couple of hours ago and I'm already integrating them into my workflow. It's also given me a bit of an "Aha! So that's how you can use different palettes in different applications" moment that's going to keep me busy for a while. Thank you!
I'm sorry, I tried to replicate the problem, but can't. It works here with a project with foreign characters (i copy-pasted the characters in one of your previous message). As long as the project has at least one existing task, it works.
A couple of things I ran into that I hope can be addressed:
I use emoji in my project names. The "Make Task" action doesn't seem to like that, since I get an exception, and then this is shown in Engine.log:
2019-11-18 15:01:20 /Users/juliant/Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions/Omnifocus Make Task/Action.scpt: execution error: OmniFocus got an error: Can’t get flattened project 1 of default document whose name = "üå± Catch-All". Invalid index. (-1719)
I managed to test this with projects without emoji, and it works fine. For clarity, the project name is: " Catch-All". This seems to be affecting tags as well. I use emoji in pretty much all tags/projects, so this kinda makes it a non-starter for me.
Is it possible to specify more than one tag? The "Make Task" action is asking for a Context, which is a "deprecated" terminology since we use tags everywhere in OF now.
Any help you could give would be greatly appreciated. Thanks!
Hi, I'm discovering more and more different ways people use OmniFocus! I didn't even think about using emojis in project names. However this should be something that I should be able to test when I have the time.
For the multiple tag thing, I originally developed the action pack for OmniFocus 2, before tags were possible. I know I already tweaked some actions to take that into account, but as a strict GTD practitioner I don't use multiple tags, so I never modified the original actions to allow multiple tags. I'll check if I can modify it easily, probably using comma separated tags as the parameter.
You'll probably need a bit of patience though, I only do this in my spare time.