Reputation: 1189
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)
Upvotes: 0
Views: 501
Reputation: 66
This has been fixed in version 1.0.1 of NodObjC
Upvotes: 1