19

I've used JavaScript and some frameworks (jQuery, Prototype, some node.js) for client-side web programming, but never on the desktop, where I do most of my scripting work in either Python or Bash.

But IMHO, JavaScript would make a great scripting language if used outside of the browser. Has anyone tried this? Can JavaScript be an adequate replacement for Python/Perl/Bash for quick and dirty scripting tasks?

10
  • 7
    There is a section on the Javascript Wikipedia article titled "Uses outside web pages", which documents quite a few instances of Javascript used exactly as you describe. Please do some research before asking.
    – yannis
    Commented Jan 26, 2012 at 8:25
  • 7
    Yannis, is there such a rule in SE sites? I think SE aims to be one part wiki as well, meaning that only chatty, off-topic, non-answerable or extremely low quality questions should be closed. Commented Jan 26, 2012 at 8:42
  • 3
    @TamásSzelei Actually there is a rule, summarized as "Do your homework". And SE is part wiki, but in the sense that every post is editable by everyone, not in the sense of building a general reference. Jeff Atwood summarizes the "official" policy in this meta answer.
    – yannis
    Commented Jan 26, 2012 at 9:00
  • 3
    @Yannis: I have looked into this topic myself and the resources on the internet pertaining to this subject are severely lacking. Futhermore, I appreciate that the question was asked in a forum where intelligent, knowledgeable members of the computing community can chime in with their experience, opinions, and suggestions. In regards to topics that rely heavily on subjective opinion, I would trust the words of a stackexchange member with 20k rep over a wikipedia article ANY DAY. Commented Jan 26, 2012 at 9:19
  • 3
    @ajax81 If there were evidence of previous research in the question, it would have been a perfectly fine question to ask. If you truly value the community as much as you say, I'm certain you don't want to waste anyone's time, and you would have been kind enough to share your research with us and ask only on what is not sufficiently answered in various general reference sites. I'm not suggesting Wikipedia as an alternative to the SE hive mind, what I'm saying is exactly the opposite, we aren't an alternative, ask when Wikipedia is not enough (but please tell us how & why it's not enough).
    – yannis
    Commented Jan 26, 2012 at 9:25

6 Answers 6

23

Yes! You definitely can do that with Node.js or Rhino. For example the coffeescript compiler is nothing but a node.js script.

I will admit that it is not generally my first choice for desktop scripting but I see no reason why it would not work quite well for a number of tasks.

0
11

Windows has a component called Windows Scripting Host that allows you to automate administration and even mimic user activity to some extent through JScript.

Update in 2017: OSX now allows you to automate desktop tasks with Javascript. What was previously possible through AppleScript is now possible through Javascript.

6

I use javascript mainly for everything because I like it and my daily job is heavily influenced by it. Now what do I mean by saying everything:

  1. Custom tools(with node-webkit you are able to bring desktop experience)

  2. Custom scripts to run on my machine via node.js

  3. Mobile apps. I don't even need PhoneGap as I am pretty comfortable with visiting URL.

  4. Backend for my web apps with node.js . I can access filesystem and databases so what am I lacking? Well.. A mature enough framework and I hope this will be fixed in the feature.

  5. Well of course fancy jQuery stuff for websites.

Misc:

  1. I solve all the coding katas with javascript(project euler, codewars)

  2. I implement algorithms I am interested in Javascript

  3. 3D experiments with three.js and webgl.

Someone will beat me because of performance but I want to satisfy performance of writing code and understanding a topic instead of making it run blazingly fast.

And as for desktop experience, for me working with HTML and CSS for user interface is the most pleasant way.

4

Qt offers QtScript. Wikipedia said:

QtScript is a scripting engine that has been part of the Qt cross-platform application framework since version 4.3.0.

The scripting language is based on the ECMAScript standard with a few extensions, such as QObject-style signal and slot connections.[1] The library contains the engine, and a C++ API for evaluating QtScript code and exposing custom QObject-derived C++ classes to QtScript.

If you don't know what Qt is: It's a cross-platform application framework in C++. It is good in taking complexity out of C++ front-end development, and is also supported on mobile systems. It has been long ago since I last developed with Qt but I liked it.

With QtScript I could imagine that one writes a minimal GUI and does the application logic in JavaScript.

1
  • 1
    With Qt5, javascript get's an even bigger role with the new QML/QtQuick GUI framework (uses embedded javascript for managing the UI).
    – Macke
    Commented Feb 21, 2014 at 9:40
0

If you're just talking 'purely outside the browser' then look at tools like Appcelerator and Servoy, both of which use Javascript for coding, which ultimately gets turned into Java.

-1

I am using JScript.net right now to create an intelligent command line interface. Its working out pretty well for this project because eval() comes in handy, but not everything works as you expect (its not pure js). But it does offer some RAD. I think it would make a good prototyping platform. Its kind of weird being in a no-mans-land between js and .net though. (Its obsolete too, so hard to find good resources on it)

Not the answer you're looking for? Browse other questions tagged or ask your own question.