>如何检查一个人是否有化身?
您不需要错误处理程序。只是使用
image of [somebody] is missing value
,在哪里
[somebody]
是通讯簿用户的说明符。
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
>如何取消设置?
要删除某人的图像,请将其设置为
missing value
。
>如何从文件加载虚拟人物?
要从文件加载图像,请将其读取为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中,如果您希望
view the scripting dictionary
到
download
将图像加载到文件中,然后如上所述加载它。
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的
Image Events
可以读取pict、photoshop、bmp、quicktime image、gif、jpeg、macpaint、jpeg2、sgi、psd、tga、text、pdf、png和tiff格式。我希望
read
(
2
)命令支持相同的功能。请注意,图像类型
阅读
命令被指定为
OSTypes
. 通讯簿仅支持TIFF。
>是否可以使用AppleScript将现有的虚拟人物复制到剪贴板?
您可以使用
set the clipboard to
尽管你可能需要
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