我正试图用Node.js使用NodObjC创建一个可可应用程序。我一直在创建一个应用程序,它只作为MacOS服务器运行在HTTP上。
NodObjC https://github.com/TooTallNate/NodObjC
我想像这样在StatusBar上显示带有图标的服务器状态。

我试过这样做:
var $ = require('NodObjC');
$.import('Foundation');
$.import('Cocoa');
var systemStatusBar = $.NSStatusBar('systemStatusBar');
var _statusItem = systemStatusBar('statusItemWithLength', $.NSVariableStatusItemLength);
_statusItem('setHighlightMode', 'YES');
var title = $.NSString('stringWithUTF8String', 'Test');
_statusItem('setTitle', title);
_statusItem('setMenu', systemStatusBar);但是这段代码会导致错误。
node[15637:707] -[NSStatusItem _setMenuOwner:]: unrecognized selector sent to instance 0x10816d810
tmp/node_modules/NodObjC/lib/id.js:158
throw e
^
NSInvalidArgumentException: -[NSStatusItem _setMenuOwner:]: unrecognized selector sent to instance 0x10816d810
at Function.msgSend (tmp/node_modules/NodObjC/lib/id.js:156:21)
at id (tmp/node_modules/NodObjC/lib/id.js:119:15)
at tmp/test.js:22:3
at wrapper (tmp/node_modules/NodObjC/lib/imp.js:49:20)
at Number.<anonymous> (tmp/node_modules/NodObjC/node_modules/node-ffi/lib/callback.js:23:23)
at ForeignFunction.proxy (tmp/node_modules/NodObjC/node_modules/node-ffi/lib/foreign_function.js:84:20)
at Function.msgSend (tmp/node_modules/NodObjC/lib/id.js:153:23)
at id (tmp/node_modules/NodObjC/lib/id.js:119:15)
at Object.<anonymous> (tmp/test.js:30:1)
at Module._compile (module.js:456:26)我找不到解决这个错误的办法。有人能给我一些建议吗?
发布于 2013-07-29 22:11:09
我终于想出了自己该怎么做。
var $ = require('NodObjC')
$.import('Cocoa')
var pool = $.NSAutoreleasePool('alloc')('init'),
app = $.NSApplication('sharedApplication'),
statusMenu;
// set up the app delegate
var AppDelegate = $.NSObject.extend('AppDelegate')
AppDelegate.addMethod('applicationDidFinishLaunching:', 'v@:@', function (self, _cmd, notif) {
var systemStatusBar = $.NSStatusBar('systemStatusBar');
statusMenu = systemStatusBar('statusItemWithLength', $.NSVariableStatusItemLength);
statusMenu('retain');
var title = $.NSString('stringWithUTF8String', "Hello World");
statusMenu('setTitle', title);
})
AppDelegate.register()
var delegate = AppDelegate('alloc')('init')
app('setDelegate', delegate)
app('activateIgnoringOtherApps', true)
app('run')
pool('release');

http://masashi-k.blogspot.com/2013/07/statusbar-with-nodobjc.html
https://stackoverflow.com/questions/17904610
复制相似问题