Contactsに登録してある自分の写真をPNGでデスクトップに保存する
住所録(Contacts.app)に登録してある自分の写真をPNG形式でデスクトップに保存するAppleScriptです。
住所録情報については、Contacts.appに直接アクセスして処理することも可能ですが、ここではAddressBook.frameworkを用いた方法をご紹介します。
— 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
More from my site
- 住所録から苗字を抽出して1文字以上の苗字をリスト出力 住所録から苗字を抽出して1文字以上の苗字をリスト出力
- Wikipedia経由で2つの単語の共通要素を計算するcommon elements Lib Script Library Wikipedia経由で2つの単語の共通要素を計算するcommon elements Lib Script Library
- 画面上の指定座標にマウスカーソルを強制移動させてクリック 画面上の指定座標にマウスカーソルを強制移動させてクリック
- checkboxLibをアップデート(3)sdefにサンプルドキュメントを入れる checkboxLibをアップデート(3)sdefにサンプルドキュメントを入れる
- checkboxLibをアップデート checkboxLibをアップデート
- アイテム番号リストをもとに、ヒットしなかった項目を返す アイテム番号リストをもとに、ヒットしなかった項目を返す