Contactsに登録してある自分の写真をPNGでデスクトップに保存する

住所録(Contacts.app)に登録してある自分の写真をPNG形式でデスクトップに保存するAppleScriptです。

住所録情報については、Contacts.appに直接アクセスして処理することも可能ですが、ここではAddressBook.frameworkを用いた方法をご紹介します。

AppleScript名:Contactsに登録してある自分の写真をPNGでデスクトップに保存する
— Created 2016年04月02日 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AddressBook"

set imgData to current application’s ABAddressBook’s sharedAddressBook()’s |me|()’s imageData()

set aDesktopPath to (current application’s NSProcessInfo’s processInfo()’s environment()’s objectForKey:("HOME"))’s stringByAppendingString:"/Desktop/"
set savePath to aDesktopPath’s stringByAppendingString:((current application’s NSUUID’s UUID()’s UUIDString())’s stringByAppendingString:".png")

saveTIFFDataAtPathAsPNG(imgData, savePath) of me

–NSImageを指定パスにPNG形式で保存
on saveTIFFDataAtPathAsPNG(anImage, outPath)
–set imageRep to anImage’s TIFFRepresentation()
set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:anImage
set pathString to current application’s NSString’s stringWithString:outPath
set newPath to pathString’s stringByExpandingTildeInPath()
set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSPNGFileType) |properties|:(missing value))
set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean
return aRes –成功ならtrue、失敗ならfalseが返る
end saveTIFFDataAtPathAsPNG

(Visited 254 times, 1 visits today)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>