12

applescriptOutlookに新しいメッセージがあるときにうなり声の通知を発生させるを変更しようとしています。元のスクリプトはこちらです。

私のif声明では、フォルダが削除済みアイテム、迷惑メール、または送信済みアイテムのいずれかである場合、通知を発行しないようにしようとしています。

ステートメントは次のとおりです。

if folder of theMsg is "Junk E-mail" or "Deleted Items" or "Sent Items" then
    set notify to false
else
    set notify to true
end if

applescriptは、私が追加した複数のis/またはアイテムを気に入らないようです。複数の基準を含める方法はありますか、それともネストされたif / thenを作成する必要がありますか?

4

4 に答える 4

16

AppleScriptで条件を連鎖させる正しい方法ifは、完全な条件を繰り返すことです。

if folder of theMsg is "A" or folder of theMsg is "B" or folder of theMsg is "C" then

–左側の引数の暗黙の繰り返しはありません。これを行うためのよりエレガントな方法は、左側の引数をアイテムのリストと比較することです。

if folder of theMsg is in {"A", "B", "C"} then

これは同じ効果があります(これは、リストへのテキストの暗黙の強制に依存していることに注意してください。これは、コンテキストによっては失敗する可能性があります。その場合は、左を明示的に強制します。つまり)。tell(folder of theMsg as list)

于 2012-05-09T19:59:58.773 に答える
1

条件文に複数の基準を含める場合は、条件文全体を書き直す必要があります。これは時々非常に面倒なことがありますが、それはAppleScriptが機能する方法です。あなたの表現は次のようになります:

if folder of theMsg is "Junk E-mail" or folder of theMsg is "Deleted Items" or folder of theMsg is "Sent Items" then
    set notify to false
else
    set notify to true
end if

ただし、回避策があります。すべての基準をリストに初期化し、リストに一致するものが含まれているかどうかを確認できます。

set the criteria to {"A","B","C"}
if something is in the criteria then do_something()
于 2012-05-09T20:02:33.790 に答える
0

試す:

repeat with theMsg in theMessages
        set theFolder to name of theMsg's folder
        if theFolder is "Junk E-mail" or theFolder is "Deleted Items" or theFolder is "Sent Items" then
            set notify to false
        else
            set notify to true
        end if
    end repeat

他の2つの答えは複数の基準を正しく解決しますが、指定しない限り機能しませname of theMsg's folderん。

mail folder id 203 of application "Microsoft Outlook"
于 2012-05-09T20:08:17.467 に答える
0

「複数の条件がある場合はapplescript」をグーグルで検索してこの投稿に出くわしましたが、ここで期待していたコードスニペットに出くわしませんでした(情報提供のみを目的として):

複数の条件を再帰的にスキャンすることもできます。次の例は次のとおりです。—送信者の電子メールアドレス(Arg 1.1)何か(Arg 2.1.1および2.1.2)が含まれているかどうかを調べて、スクリプトをすぐに停止し、「通知」=> true(Arg 3.1)します。—フォルダー/メールボックス(Arg 1.2)が "2012"(Arg 2.2.1)で始まるが、フォルダー2012-ABまたはC(Arg 2.2.2)ではないかどうかを確認する3つのフォルダのうち停止して何もしません=> false(Arg3.2)。

if _mc({"\"" & theSender & " \" contains", "\"" & (name of theFolder) & "\""}, {{"\"@me.com\"", "\"Tim\""}, {"starts with \"2012\"", "is not in {\"2012-A\", \"2012-B\", \"2012-C\"}"}}, {true, false}) then
    return "NOTIFY "
else
    return "DO NOTHING "
end if

-シェルスクリプトによる複数の条件の比較

on _mc(_args, _crits, _r)
    set i to 0
    repeat with _arg in _args
        set i to i + 1
        repeat with _crit in (item i of _crits)
            if (item i of _r) as text is equal to (do shell script "osascript -e '" & (_arg & " " & _crit) & "'") then
                return (item i of _r)
            end if
        end repeat
    end repeat
    return not (item i of _r)
end _mc

https://developer.apple.com/library/mac/#documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_about_handlers.html#//apple_ref/doc/uid/TP40000983-CH206-SW3

于 2013-07-11T20:59:01.123 に答える