1

私は次のアップルスクリプトを持っています。IMを受信したときにichatで実行するように設定しました。それは新しいメッセージのうなり声を介して私に通知します:

on notify_growl(theName, theTitle, theDescription, theImage)
    display dialog theImage
    tell application "Growl"
        notify with name theName title theTitle description theDescription application name "iChat" image theImage
    end tell
end notify_growl

using terms from application "iChat"
    -- register the app with growl
    tell application "Growl"
        set the allNotificationsList to {"Message Received"}
        set the enabledNotificationsList to {"Message Received"}
        register as application "iChat" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "iChat"
    end tell

    -- handle the iChat events
    on message received theMessage from theBuddy for theChat
        if ((application "iChat" is not frontmost) or (status of application "iChat" is equal to away)) then
            notify_growl("Message Received", name of theBuddy, theMessage, image of theBuddy)
        end if
    end message received

    on received text invitation theMessage from theBuddy for theChat
        accept theChat
        if ((application "iChat" is not frontmost) or (status of application "iChat" is equal to away)) then
            notify_growl("Message Received", name of theBuddy, theMessage, image of theBuddy)
        end if
    end received text invitation
end using terms from

問題は、バディに画像が関連付けられていない場合、エラーが発生することです。そのため、notify_growlにifステートメントを追加します。ここで、theImageが空白、null、またはその他の場合、うなり声は画像がありません。表示ダイアログtheImageが空の場合、「msng」というダイアログが表示されます

4

2 に答える 2

2

これを試して ;)

on notify_growl(theName, theTitle, theDescription, theImage)
    tell application "Growl"
        try
            notify with name theName title theTitle description theDescription application name "iChat" image theImage
        on error
            notify with name theName title theTitle description theDescription application name "iChat"
        end try
    end tell
end notify_growl
于 2011-10-09T00:33:23.340 に答える
2

に対してテストしmissing valueます。AppleScriptのnull/未定義の値の類似物です。あなたの場合、画像を省略したい場合は、次のようになります。

on notify_growl(theName, theTitle, theDescription, theImage)
    tell application "Growl"
        if theImage is missing value then
            notify with name theName title theTitle description theDescription ¬
                application name "iChat"
        else
            notify with name theName title theTitle description theDescription ¬
                application name "iChat" image theImage
        end if
    end tell
end notify_growl

代わりにデフォルトの画像がある場合は、次のように書くことができます

on notify_growl(theName, theTitle, theDescription, theImage)
    tell application "Growl"
        if theImage is missing value then set theImage to defaultImage
        notify with name theName title theTitle description theDescription ¬
            application name "iChat" image theImage
    end tell
end notify_growl

デフォルトの画像の場合、次のようにすることができます。

set defaultImageFile to open for access POSIX file "/some/file/path"
set defaultImage to read defaultImageFile as "JPEG"
close defaultImageFile

もっと簡単な方法があるかもしれませんが、これはあなたにイメージを与えるでしょう。ただし、十分に遅いため、この場合は機能しない可能性があります。

于 2011-10-09T06:13:52.567 に答える