如何测试AppleScript中的图像是否为空?

如何测试AppleScript中的图像是否为空?,applescript,ichat,Applescript,Ichat,我有以下的应用程序脚本。当我收到即时消息时,我已将其设置为在ichat中运行。它通过咆哮通知我新消息: on notify_growl(theName, theTitle, theDescription, theImage) display dialog theImage tell application "Growl" notify with name theName title theTitle description theDescription appli

我有以下的应用程序脚本。当我收到即时消息时,我已将其设置为在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语句,如果图像为空,或者为null,或者其他任何形式,则可以在图像中进行咆哮。“显示”对话框图像为空时,会显示一个显示“msng”的对话框(请尝试此操作;)

试试这个;)


针对
缺失值
、AppleScript模拟的空/未定义值进行测试。在您的情况下,如果您只想省去图像,则会显示如下所示:

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

也许有一个更简单的方法,但这会给你一个形象。但是,它的速度非常慢,在您的情况下可能无法工作。

针对
缺失值进行测试,这是AppleScript模拟的空值/未定义值。在您的情况下,如果您只想省去图像,则会显示如下所示:

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

也许有一个更简单的方法,但这会给你一个形象。但是,它的速度非常慢,在您的情况下可能不起作用。

+1因为您的答案是一个解决方案,但我给了@antal最好的答案,因为他直接回答了我的问题+1因为您的答案是一个解决方案,但我给了@antal最好的答案,因为他直接回答了我的问题