I’m integrating the QuickEntry with my Outlook workflow, and every thing looks great. Now I’m trying to make the task note a bit more beautiful with RichText.
I look on lots of forums and posts but apparently no one needed to do this:
Create a RichText note equivalent to the following HTML:
I’m aware of this post (Making link clickable in OF2), but besides not having a clear answer for the question, it’s using Applescript instead of Javascript. Does anyone know how to do this?
I’m not familiar with Javascript for Automation, but I can give you a starting point.
Try this code. It set the note of value of first tree of content of front document window
var of = Application('OmniFocus'),
oValue = of.defaultDocument.documentWindows[0].content.trees[0]['value']();
of.strictPropertyScope = true
of.strictCommandScope = true
oValue.note = 'OmniFocus'
oValue.note.paragraphs[0].style.attributes['link'].value = 'https://www.omnigroup.com/omnifocus';
I think I got it. I have to add the task to the quick entry in order to have a RichText note.
I couls use the .insert() method on the RichText class to add stuff to it but I need to find how to use it. Its documentation says:
insertmethod : Insert text in the middle of an existing blob of text. insert text : the string to insert. at: location specifier : Where to insert the text.
[using: Style] : The style to use when inserting the text. If missing, the default style for this text will be used.
But I have no idea how to define the “at” argument of it. I tried:
of.quickEntry.inboxTasks[num - 1].note.insert({
text: "This is a test",
at: 0
});
In Applescript, the at parameter would be, for example:
at before paragraphs
The problem is, I think, relative reference forms aren’t working very well in JXA. This is my hipotesis based on my investigation.
One option would be: create the note text and then set the value of the attribute in the desired paragraph.
Example:
var of = Application('OmniFocus'),
ofDoc = of.defaultDocument,
inbox = ofDoc.inboxTasks;
//of.strictPropertyScope = true
//of.strictCommandScope = true
task = of.InboxTask({name: 'New Task', note:'Welcome to OmniFocus\n\nOmniFocus HomePage'});
num = of.quickEntry.inboxTasks.push(task);
of.quickEntry.inboxTasks[num - 1].note.paragraphs[2].style.attributes['link'].value = 'https://www.omnigroup.com/omnifocus';
of.quickEntry.open();
As it happens I’m not an OF user so I can’t test specifically, but generally, objects in JXA dictionaries tend to have .before() and .after() functions on them, which should return values of the ‘location specifier’ variety.