0

我正在尝试使用 AppleScript 来查找现有的 OmniFocus 任务并根据某些规则附加项目和上下文。这是有效的,除了:

当我创建新任务时,我试图note直接复制属性。在 OmniFocus 的字典中,它说该note属性是“富文本”,但在新任务中它似乎已成为纯文本(特别是,我想保留的文本中的链接正在消失,但还有其他风格正在消失)

on set_project_and_context(the_task, the_project, the_context)
    tell application "OmniFocus"
        tell front document
            set task_name to name of the_task
            set task_note to note of the_task
            set new_text to task_name & " ::" & the_project & " @" & the_context
            set new_tasks to (parse tasks into with transport text new_text with as single task)
            set new_task to item 1 of new_tasks
            set due date of new_task to missing value
            set note of new_task to task_note # <- HERE IS WHERE I'M TRYING TO COPY THE NOTE
            delete the_task
        end tell
    end tell
end set_project_and_context

我是 AppleScript 新手,因此感谢您提供任何帮助;)

4

3 回答 3

1

您不能直接复制注释属性,因为新注释将是没有所有样式和链接的纯文本。要保留格式,您需要设置style属性的每个段落的note属性。我添加了一个处理程序来设置它。

也许这有帮助。

代码:

on set_project_and_context(the_task, the_project, the_context)
    tell application "OmniFocus"
        tell document 1
            set task_name to name of the_task
            set task_note to note of the_task
            set new_text to task_name & " ::" & the_project & " @" & the_context
            set new_tasks to (parse tasks into it with transport text new_text with as single task)
            set new_task to item 1 of new_tasks
            set due date of new_task to missing value
            my SetNote(the_task, new_task) -- NEW HANDLER
            delete the_task
        end tell
    end tell
end set_project_and_context

on SetNote(old_task, new_task)
    using terms from application "OmniFocus"
        set text of note of new_task to text of note of old_task
        set lst_paragraphs to (every paragraph of note of old_task)
        repeat with i from 1 to count lst_paragraphs
            set style of paragraph i of note of new_task to (style of paragraph i of note of old_task)
        end repeat
    end using terms from
end SetNote
于 2017-08-23T18:51:57.927 回答
0

AppleScript 本身不理解带样式的文本,并且没有标准的方式让应用程序返回带有样式信息的文本,因此:

set task_note to note of the_task

仅返回纯文本。

您需要告诉应用程序将富文本直接从一个属性复制到另一个属性:

set note of new_task to note of the_task

该命令是否有效取决于应用程序的脚本支持的实现情况;你只需要试试看。

于 2017-08-24T09:04:29.470 回答
0

通过创建新任务并将其项目和上下文分配给现有任务,我实际上有点不直观地解决了这个问题,这样我就不需要重新创建笔记。可能有更好的方法来获取项目和上下文,尽管我找不到更好的方法来找到嵌套的项目/上下文

on set_project_and_context(the_task, project_text, context_text)
    tell application "OmniFocus"
        tell front document
            set task_name to name of the_task
            set new_text to task_name & " ::" & project_text & " @" & context_text
            set new_tasks to (parse tasks into with transport text new_text with as single task)
            set new_task to item 1 of new_tasks

            set context of the_task to context of new_task
            set the_project to containing project of new_task
            set project_name to name of the_project
            move the_task to end of tasks of the_project
            delete new_task
        end tell
    end tell
end set_project_and_context
于 2017-08-25T01:35:17.813 回答