0

メッセージの先頭に定義済みのテキストを挿入するアップルスクリプトを作成しようとしています。これは私が現在持っているものです:

set msgClass to (choose from list {"Green", "Blue", "Purple"} with title "Choose:")
if result is false then
    stop
else
    set msgClasstxt to the result
    set msgClasstxt to "Classification: " & msgClasstxt

    tell application "System Events"
        key code 126 using {command down}
        keystroke return
        keystroke return
        key code 126 using {command down}
    end tell
tell application "Microsoft Outlook" to set selection to msgClasstxt
end if

これを行うためのより良い方法があると確信していますが、意図は次のとおりです。

  • CMD+Up でホームに戻る
  • 空行を 2 行作成する
  • 家に帰る
  • テキストを挿入

私の問題は、キーストロークが実行される前にテキストが挿入されていることです。うっとうしい。誰でも助けることができますか?

4

2 に答える 2

0

キーストロークやその他の GUI タスクは、最前面のアプリケーションに入力されます。そのため、これらのアクションを実行する直前に、対象とするアプリケーションを常にアクティブ化する必要があります。したがって、システム イベント コードの直前に次を配置することをお勧めします。アプリケーションが最前面にあると思われる場合でも、念のためにとにかくこれを行う必要があります。

tell application "Microsoft Outlook" to activate
delay 0.2

また、他のコメントで示唆されているように、コンピューターがコードを物理的に実行する時間を確保するために、GUI コードの各行の間に短い遅延が必要です。

したがって、遅延を使用してアプリケーションをアクティブにします。それはあなたを助けるはずです。

于 2015-01-29T15:21:05.660 に答える
0

だから、これは私がやったことです: -現在アクティブなメッセージウィンドウを確実に処理するための規定を追加 -そのウィンドウをアクティブにする -システムイベントを介してすべてのアクションを実行

tell application "Microsoft Outlook" to get the id of the first window
set currentWindow to the result

set msgClass to (choose from list {"Green", "Blue", "Purple"} with title "Choose:")

if the result is false then
    stop
else
    set msgClasstxt to "Classification: " & the result
    tell application "Microsoft Outlook"
        activate window currentWindow
        tell application "System Events"
            key code 126 using {command down}
            keystroke return
            keystroke return
            key code 126 using {command down}
            keystroke msgClasstxt
        end tell
    end tell
end if

最初の行が機能するのは、Outlook が最前面のウィンドウを最初に一覧表示するためです。これは私が今のところ欲しいことをします。

于 2015-01-30T15:56:13.250 に答える