Using Standard C Libraries with Yosemite JavaScript

The documentation at https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/index.html indicates that a number of standard C / Objective-C libraries may be used in JavaScript via the ObjC.import() mechanism.

Please consider the following short program:

Screen Shot 2014-10-24 at 7.48.32 PM

Here’s what the program looks like when run from osascript ( note that since I didn’t try to “script” osascript itself, I no longer received the warning message I had mentioned in an earlier post… )

Screen Shot 2014-10-24 at 7.50.11 PM

I can then enter a line of text.

Screen Shot 2014-10-24 at 7.52.00 PM

I added the $.exit(0); line at the bottom to avoid the appearance of the last evaluated expression on the standard output line.

There are some interesting libraries listed in the Apple documentation.  I think there’s a lot of potential for some cool JavaScript / C library hybrid programs.

Advertisements

About Jim Lawless

I've been programming computers for about 36 years ... 30 of that professionally. I've been a teacher, I've worked as a consultant, and have written articles here and there for publications like Dr. Dobbs Journal, The C/C++ Users Journal, Nuts and Volts, and others.
This entry was posted in Programming and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s