如何使用AppleScript操作通讯簿图像?

如何使用AppleScript操作通讯簿图像?,applescript,addressbook,Applescript,Addressbook,你如何检查一个人是否有头像?你怎么取消它?如何从文件中加载化身?来自网络、Facebook、gravatar?AppleScript可以读取哪些图像类型?是否可以使用AppleScript将现有化身复制到剪贴板 编辑 好的,我知道如何检查一个人是否有头像 on run using terms from application "Address Book" my hasImage(person (random number from 1 to length of (get

你如何检查一个人是否有头像?你怎么取消它?如何从文件中加载化身?来自网络、Facebook、gravatar?AppleScript可以读取哪些图像类型?是否可以使用AppleScript将现有化身复制到剪贴板

编辑

好的,我知道如何检查一个人是否有头像

on run
    using terms from application "Address Book"
        my hasImage(person (random number from 1 to length of (get people of application "Address Book") of application "Address Book") of application "Address Book")
    end using terms from
end run

on hasImage(myPerson)
    using terms from application "Address Book"
        try
            set garbage to image of myPerson
            garbage
            true
        on error number -2753
            false
        end try
    end using terms from
end hasImage
>你如何检查一个人是否有头像? 您不应该需要错误处理程序。只需使用[someone]的
图像缺少值
,其中
[someone]
是地址簿联系人的说明符

tell application "Address Book"
    image of some person is missing value
end tell
用法:

tell application "Address Book"
    set somebody to some person
    if image of somebody is missing value then
        display dialog name of person & " doesn't have an image."
    else
        display dialog name of person & " has an image."
    end if
end tell
>你怎么取消它? 要删除人物图像,请将其设置为
缺少值

>如何从文件中加载化身? 要从文件加载图像,请将其作为TIFF数据读取:

tell application "System Events"
    set imgfile to file "AENewman.jpg" of folder "friends" of pictures folder
end tell
set imgfd to open for access imgfile
set img to read imgfd as "TIFF"

tell application "Address Book"
    set myFriend to item 1 of ¬
        (people whose first name is "Alfred" and last name is "Newman")
    set (image of myFriend) to img
end tell

close access imgfd
>来自网络、Facebook、gravatar? 您可以使用URL访问脚本(如果愿意,可以在/System/Library/ScriptingAdditions/URL Access Scripting.app中)将图像下载到文件中,然后如上所述加载它

on setABImage for somebody from |url|
    tell application "System Events" to set tempFile to ¬
        make new file at end of temporary items folder of user domain
    set tempPath to path of tempFile
    tell application "URL Access Scripting" to download |url| ¬
        to tempPath replacing yes
    set imgfd to open for access tempFile
    tell application "Address Book" to set (image of somebody) ¬
        to (read imgfd as "TIFF")
    close access imgfd
    tell application "System Events" to delete tempFile
end setABImageURL
>AppleScript可以读取哪些图像类型? AppleScript可以读取PICT、Photoshop、BMP、QuickTime图像、GIF、JPEG、MacPaint、JPEG2、SGI、PSD、TGA、文本、PDF、PNG和TIFF格式。我希望该命令支持同样的操作。请注意,
read
命令中的图像类型指定为。通讯簿仅支持TIFF

>是否可以使用AppleScript将现有化身复制到剪贴板? 尽管您可能需要一个
as
子句来将剪贴板设置为内容,而不是引用,但您可以使用将剪贴板设置为任何内容

tell application "Address Book" to set the clipboard to ¬
    the image of item 1 of (person whose name is "Alfred E Newman") as data

请注意,您可以回答自己的问题。上面的答案应该贴出来。outis真的知道他们的AppleScript。这很有帮助,而且格式也很好。非常感谢。