Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
6  
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 Rizos Jan 26 '12 at 8:25
4  
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. –  Tamás Szelei Jan 26 '12 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 Rizos Jan 26 '12 at 9:00
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 Rizos Jan 26 '12 at 9:25
3  
@ajax81 The OP has asked quite a few of great questions, he may be fairly new to the site but I feel he is extremely well versed to its purpose and scope. To be frank I was a bit surprised to read this question. Anyways, this comment thread I think presents my approach sufficiently, and is readable by everyone, so in this instance I don't think there's much room for further elaboration. –  Yannis Rizos Jan 26 '12 at 9:51
show 4 more comments

6 Answers

up vote 10 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
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 Feb 21 at 9:40
add comment

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(my current goal is a simple raytracer).

  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.

Another plus for javascript is because it's kinda lispy so I can read SICP and do not hesitate about implementing some of the solutions in Javascript.

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

share|improve this answer
add comment

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)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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