EzDevInfo.com

NodObjC

The Node.js ⇆ Objective-C bridge Index | NodObjC v0.0.12

$.NSUserNotificationCenter('defaultUserNotificationCenter') returns null

i am trying to fire up a notification to the notification - center through node and NodObjC and the problem is:

    $.NSUserNotificationCenter('defaultUserNotificationCenter')

returns always null instead of an object to able to call the "deliverNotification" method ?

Does anyone has expireience with NodObjC ?


Source: (StackOverflow)

Getting window location of open apps via NodObjC

I've been messing around with the node.js module NodObjC recently (very cool module btw), I threw together a simple module, macmouse, that gives you the ability to control your mouse through node.js, now I'm trying to fetch information on open windows via CGWindowListCopyWindowInfo (the idea is to do something fun using that information and the virtual mouse functionality). I don't have much experience with Objective C but I stumbled upon an example of this in a blog post:

http://b2cloud.com.au/tutorial/monitoring-any-window-in-os-x/

I tested it out in Xcode,

#import "Foundation/Foundation.h"
#import "Cocoa/Cocoa.h"

NSArray* windows = CFBridgingRelease(CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID));
NSLog(@"%@", windows);

and it prints out all the data I want and more, but now I'm stuck on how to do this using the NodObjC module.

Here's my go at it (using NodObjC v1.0.0):

var $ = require('NodObjC');
$.framework('Foundation');
$.framework('Cocoa');
var pool = $.NSAutoreleasePool('alloc')('init');

var windowList = $.CFBridgingRelease($.CGWindowListCopyWindowInfo($.kCGWindowListOptionAll, $.kCGNullWindowID));

console.log(windowList);

pool('drain');

but I'm getting the following error:

/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/lib/_foreign_function.js:55
  throw e
        ^
TypeError: error setting argument 0 - writePointer: Buffer instance expected as third argument
at Object.writePointer (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:740:11)
at Object.set (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:482:13)
at Object.alloc (/Users/loknar/Desktop/nodobjc_stuff/node_modules/ffi/node_modules/ref/lib/ref.js:514:13)
at ForeignFunction.proxy (/Users/loknar/Desktop/node_robot/nodobjc_stuff/ffi/lib/_foreign_function.js:50:22)
at Function.unwrapper (/Users/loknar/Desktop/nodobjc_stuff/node_modules/NodObjC/lib/core.js:297:31)
at Object.<anonymous> (/Users/loknar/Desktop/nodobjc_stuff/listOfWindows.js:44:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

What's going wrong here? (I've also posted this question on the NodObjC's issue page)


Source: (StackOverflow)

Advertisements

NSStatusBar with NodObjC

I'm trying to create a cocoa app with Node.js using NodObjC. I have been creating an app which runs on only MacOS X as HTTP server.

NodObjC https://github.com/TooTallNate/NodObjC

I want to show the server status with icon on StatusBar like this. enter image description here

I tried like this:

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);

But this code causes an error

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)

I couldn't find any solution for this error. Could anybody give to me any advices?


Source: (StackOverflow)