2012-06-05 36 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