How to set column type "duration" via AppleScript?


#1

Hello everyone!

I am trying to accomplish the following. I would like to change settings (red underline squigle on screenshot below) of column type “duration” via AppleScript.

Typically, I would use “column format” property like in the screenshot below:

However, when the column is of type “duration”, the property is empty. I have asked OO support (via email) and they have directed me here. Here’s the screenshot explaining what I mean:


#2

Apparently, you can’t do that. I opened Script Debbuger and, as you say, the column format property is a record of 0 items.


#3

Do you think it’s a bug? Or a missing feature? Any workaround for this? I imagine it’s not a very popular feature (column type “duration”) since it wasn’t addressed previously (tried Google search without much lack)?


#4

I don’t know if this feature was planned. We need to ask Omni for that.
What’s your desired workflow? What do you need to accomplish? Maybe you can resort to GUI Scripting as a last step.


#5

In a nutshell, I am using OF with projects which have deadlines. Since I adhere to GTD workflow, part of the process of choosing the next action is a priority. I determine priority based on the number of the days before the deadline of the project. Currently, I use column type “number” which represents the number of days before the deadline. I figured that “duration” type would be more appropriate for this task. (I find that knowing how many days left before the actual deadline is more effective rather than looking at the due date itself)


#6

I see. What part of your workflow are you trying to automate?


#7

FWIW these settings do seem to be accessible through omniJS in the current test builds of OO 5.2

Adjusting this line at the top of the code below to match the name of your duration column:

const columnTitle = "Duration"; // Adjust as required

and then choosing OmniOutliner > Automation > Show Console, and pasting and entering the code (make sure that you have selected and copied it all)

(() => {

    // NAME OF COLUMN TO ADJUST BY SCRIPT ------------------------------------

    const columnTitle = "Duration";  // Adjust as required

    // GENERIC FUNCTION ------------------------------------------------------

    // show :: Int -> a -> Indented String
    // show :: a -> String
    const show = (...x) =>
        JSON.stringify.apply(
            null, x.length > 1 ? [x[1], null, x[0]] : x
        );

    // REFERENCE TO THE FORMATTING INTERFACE FOR A NAMED COLUMN --------------
    const colFormat = columns.byTitle(columnTitle)
        .formatter;

    // CHANGE A SETTING OR TWO -----------------------------------------------
    colFormat.hoursPerWeek = 36;
    colFormat.hoursPerDay = 6;
    colFormat.useVerboseFormat = false;

    // CHECK SETTINGS --------------------------------------------------------
    return show(2, {
        'hours per week': colFormat.hoursPerWeek,
        'hours per day': colFormat.hoursPerDay,
        'long format': colFormat.useVerboseFormat
    });
})();

We get a result which shows that the model has indeed been updated (and the editor display turns out to have changed too);


#8

Setting the column type to “duration” automatically does conversion e.g. 7 days into the week, 30 days into the month, etc. Unfortunately, the default “duration” setting is for work days so values get converted incorrectly if I change the column type after it was populated with data. My desired setting is calendar week. In a nutshell, if I could automatically convert days into more appropriate (i.e. more user-friendly) time format, that’s what I am looking to achieve with AppleScript.

In regards to OmniJS, does it mean that potentially it is possible to modify settings of column type “duration” in an undocumented way? I know for example, that, officially there is no way to create a clickable hyperlink but there is an unofficial way - link.


#9

Probably a question for Omni Support thru Help > Contact Omni, I think


#10

I see the problem. But, if you populate the outline with data and change the duration format via Applescript (but it’s not possible), you would get the same behaviour, I think.


#11

I tried asking support but they said it was outside the scope of support.

As the script is creating a new document (not amending an existing one), if I set the column type/settings correctly before populating data, it works fine (verified behaviour via manual input).