2012-06-05 33 views
0

我想用MacRuby设置我的用户的通讯簿图像。这是我到目前为止:用MacRuby设置通讯录图像

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) 

我也试过book.myCard.setImage(final.base64Encoding),顺便说一下。

我需要做些什么来完成这项工作?

谢谢!

回答

0

你必须有一个NSImage中

myImage = NSImage.alloc.initWithContentsOfFile(download) 
book = SBApplication.applicationWithBundleIdentifier("com.apple.addressbook") 
book.myCard.setImage(myImage) 
+0

完美!很棒! – dejay