如何使用 AppleScript 操作地址簿图像?
如何检查一个人是否有头像?怎么取消设置呢?如何从文件加载头像?来自网络、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
How do you check if a person has got an avatar? How do you unset it? How do you load an avatar from a file? From web, Facebook, gravatar? What image types can AppleScript read? Is it possible to copy an existing avatar to clipboard with AppleScript?
EDIT
OK, I know how to check if a person has got an avatar
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
>如何检查一个人是否有头像?
您不应该需要错误处理程序。只需使用
image of [somebody] ismissing value
,其中[somebody]
是地址簿人员的说明符。用途:
>怎么取消设置呢?
要删除人物图像,请将其设置为
缺失值
。>如何从文件加载头像?
要从文件加载图像,请将其读取为 TIFF 数据:
>来自网络、Facebook、gravatar?
您可以使用 URL Access Scripting(在 /System/Library/ScriptingAdditions/URL Access Scripting.app 中,如果您希望查看脚本字典)将图像下载到文件,然后按上述方式加载。
> AppleScript 可以读取哪些图像类型?
AppleScript 的 图像事件可以读取 PICT、Photoshop、BMP、QuickTime Image、GIF、JPEG、MacPaint、JPEG2、SGI、PSD、TGA、文本、PDF、PNG 和 TIFF 格式。我期望
read
命令支持相同的功能。请注意,read
命令中的图像类型被指定为 OSTypes。地址簿仅支持 TIFF。>是否可以使用 AppleScript 将现有头像复制到剪贴板?
您可以使用
将剪贴板设置为
,但您可能需要as
子句将剪贴板设置为内容而非参考。> How do you check if a person has got an avatar?
You shouldn't need an error handler. Just use
image of [somebody] is missing value
, where[somebody]
is a specifier for an Address Book person.Usage:
> How do you unset it?
To remove a person's image, set it to
missing value
.> How do you load an avatar from a file?
To load an image from a file, read it as TIFF data:
> From web, Facebook, gravatar?
You can use URL Access Scripting (in /System/Library/ScriptingAdditions/URL Access Scripting.app, should you wish to view the scripting dictionary) to download an image to a file, then load it as above.
> What image types can AppleScript read?
AppleScript's Image Events can read PICT, Photoshop, BMP, QuickTime Image, GIF, JPEG, MacPaint, JPEG2, SGI, PSD, TGA, Text, PDF, PNG, and TIFF formats. I expect the
read
command supports the same. Note that image types in aread
command are specified as OSTypes. Address Book only supports TIFF.> Is it possible to copy an existing avatar to clipboard with AppleScript?
You can set the clipboard to just about anything using
set the clipboard to
, though you might need anas
clause to set the clipboard to the contents rather than a reference.