5 ms·
Well, that's quite nifty. I never knew OS X had it's own javascript engine / component.
by swsieber 9y ago
Well, that's quite nifty. I never knew OS X had it's own javascript engine / component.
- deleted 9y ago[deleted]
- robterrell 9y agoYep, it's been there a while: rterrell$ /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc >>> for (var i=0; i<10; i++) { print("Hello World!", i); } Hello World! 0 Hello World! 1 Hello World! 2 Hello World! 3 Hello World! 4 Hello World! 5 Hello World! 6 Hello World! 7 Hello World! 8 Hello World! 9 undefined >>> Edit to add: the submission reminds me of the old "Commando" for MPW. Very cool.
- lloeki 9y agoWell, while I did know JSC was a standalone thing (a framework, rather) on macOS, notably due to its presence in AppleScript Editor, I did not know it had a REPL readily available, and that the jsc interpreter works for shebangs too!
- robterrell 9y agoI found out about it when using Cappuccino -- on mac os x it would build much faster using jsc instead of narwhal. For about a week after that I tried writing shell scripts using the jsc shebang... but it ended up being a lot more painful than I imagined.
- saagarjha 9y agoIt's called JavaScriptCore and it's part of iOS as well.
- poyu 9y agoCool links regarding JS in OSX * [JXA Cookbook](https://github.com/JXA-Cookbook/JXA-Cookbook https://github.com/JXA-Cookbook/JXA-Cookbook) * [JavaScript OS X App Examples](https://github.com/tylergaw/js-osx-app-examples https://github.com/tylergaw/js-osx-app-examples)
- ken 9y agoIt's also available for system automation [1], which is a highly underrated (IMHO) part of the Mac system. For my application (URL in bio), I wrote a shell script that (mostly) automatically generates the screenshots for the Mac App Store. It uses osascript(1) with some JS to set the system colors/wallpaper/language to a particular style, position the app window where I want it, take a screenshot, block out my menubar extras, crop it to the requested size, etc. OSA scripting is actually pretty powerful, but sadly the documentation is awful. Try: osascript -l JavaScript -e 'Application("System Events").appearancePreferences.appearance = "graphite"' (or "blue") [1]: https://en.wikipedia.org/wiki/AppleScript#JavaScript_for_Automation https://en.wikipedia.org/wiki/AppleScript#JavaScript_for_Aut...