Archive for the 'ABAddressBook' Category

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

Contacts.app(旧称:アドレスブック)に登録してある自分の写真をデスクトップにPNG形式で保存するAppleScriptです。

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

★Click Here to Open This Script