Frage

I am trying to set my user's Address Book Image with MacRuby. Here is what I have so far:

framework 'ScriptingBridge'
framework 'AppKit'

download = "/path.png"
data   = NSData.dataWithContentsOfFile(download)
bitmap = NSBitmapImageRep.imageRepWithData(data)
final  = bitmap.representationUsingType(NSTIFFFileType, properties: nil)

book = SBApplication.applicationWithBundleIdentifier("com.apple.addressbook")
book.myCard.setImage(final)

I have also tried book.myCard.setImage(final.base64Encoding), by the way.

What do I need to do to make this work?

Thanks!

War es hilfreich?

Lösung

You must have an NSImage

myImage = NSImage.alloc.initWithContentsOfFile(download)
book = SBApplication.applicationWithBundleIdentifier("com.apple.addressbook")
book.myCard.setImage(myImage)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top