My JavaScript book is out! Don't miss the opportunity to upgrade your beginner or average dev skills.

Tuesday, October 05, 2010

JavaScriptCore via Terminal

Just a quick one, maybe only for a new Mac comer as I am, I found truly annoying I have already Python, Ruby, and even PHP everywhere available in my command line but not JavaScript?

What The Fuck

Even Windows runs .js files natively and since ages, I wonder why on earth after I have downlaoded the whole XCode SDK "my JavaScript" was not there available for all my needs.

OK, OK, node.js is already on /bin, linked and working properly, but now I have the system default JavaScript Engine that comes automatically with WebKit or the "IE for Mac" aka Safari.

How to link jsc to bin folder

A title that produces zero outcome on Google, could be hopefully better addressed via this blog, and this is how I have solved:

sudo ln -F /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc /usr/bin

The Current folde ris the link to the latest one, all those threads about the ..../A/... folder are not automatically updated if A becomes B, as example.
So, now I can type jsc wherever I am and use JavaScript power whenever I want, writing just quit() anytime I need.
I hope this helps, it took a while for me to sort it out.


Rogério said...

I believe that the right place for such a link would be /usr/bin and not /bin.

Anyway, great tip!

Andrea Giammarchi said...

thanks Rogério, I was almost spreading around how to make not secure the whole environment :D

Changed, cheers

Unknown said...

What about installing node.js?

Andrea Giammarchi said...

What about *reading* the post? ;)

node.js is already there but it's something I need to keep updated, jsc is the core JavaScript library that is updated every time WebKit nightly asks me to update and automatically ;)

Finally, jsc is the JS by default while node.js brings V8, which is not the default in Mac (but I am using both, better than one)

Jani Hartikainen said...

I'm curious whether this provides you the same scripting facilities as other languages that are available in the shell?

I mean isn't JavaScriptCore just what runs JS, so it wouldn't really have any useful APIs for anything, while languages available by default all have (and on Windows, in JS via ActiveX)

Andrea Giammarchi said...

there are few extras, as quit() is for example, when it runs under console.

There are many parsers, JSLint and others, where JSC could be used as target engine to parse documents and provides result on >> out ;)

Unknown said...

jsc is really basic, as there are no I/O operations at all, rhino/commonjs/nodejs are better scripting environment replacements.

Except for load() and quit() there aren't many useful things you can do with the system in jsc.

{Mike : Dev} said...

Hey Andrea,
Nice tip. One minor correction to your link command on Mac OS X Tiger:

sudo ln -f /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc /usr/bin

In your command "-F" should be "-f".

Anonymous said...

Thanks for the tip, this is great!