2017-08-23 7 views
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の初心者ですので、任意の助けが高く評価されます。)

答えて

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 
1

新しいノートがすべてずにプレーンテキストになりますので、あなたが直接ノートプロパティをコピーすることはできませんスタイルとリンク。 フォーマットを保持するには、noteプロパティのすべての段落のstyleプロパティを設定する必要があります。私はそれを設定するハンドラを追加しました。

おそらくこれが役に立ちます。

コード:

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 
+0

おかげで、ネストされたプロジェクト/コンテキストを見つけるの関与それを行うには良い方法を見つけることができなかったものの、残念ながらそれは私のために働いていなかったものの、プロジェクトやコンテキストを取得するためのより良い方法は、おそらくあります。段落の中央にスタイル(線のような)があるとき。私は 'paragraph'を' word'に変更しました。これは動作しましたが、奇妙に見え、遅かったです。私は実際に別の答えとして共有する基本的に優れたアプローチを思いついた。 –

0

ので、AppleScriptの自体は書式付きテキストを理解していない、とアプリが付属スタイル情報を持つテキストを返すための標準的な方法がありません。

set task_note to note of the_task 

リターンをプレーンテキストのみ。

あなたが他の1つのプロパティから直接、リッチテキストをコピーするためにアプリケーションを指示する必要があります:

set note of new_task to note of the_task 

そのコマンドかどうかの作品は、アプリケーションのスクリプトのサポートが実装されてどれだけに依存します。あなたはそれを試して見なければなりません。

+0

私はそれを試してみると、OmniFocusにはエラーが出る。テキストまたはリッチテキスト "OSPropertyScriptText"でなければなりません。 OmniFocusのスクリプティングサポートが良くないためでしょうか? –

+0

ここではOFのコピーを持っていないので、構文を推測しています。 Omniには優れたユーザーサポートとフォーラムがありますので、最初に質問してみてください。そうでなければ、実験する。 'new_taskの注釈テキストをthe_task'の注釈テキストに設定し、' new_taskの注釈テキストを設定してthe_task'をメモするようにしてみてください。あまりにも控えめな振る舞いや不満足なドキュメントは、ほとんどの "AppleScriptable"アプリの標準的な "機能"です。時には、あなたはちょうど何かの上につまずくことを願って棒でそれを突き刺さなければならない。 – has

+0

ええ、これまでに少し経験したことがあります;)。ありがとう! –

関連する問題