住所録(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 |
More from my site
(Visited 254 times, 1 visits today)