My most important development tool....

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

xbytor

My most important development tool....

Post by xbytor »

Probably the one thing that makes me as productive as I am with PS-JS (besides xemacs, of course) is the attached script, jsh.js.

To be really productive with a scripting language, you need a command line interface to the interpreter. That way you can quickly test out new ideas either with the language or the runtime environment without having to open up an editor, create a file, save the file, run the file, (repeat as necessary).

While the UI for jsh is not quite like a real command line shell, it's as close as I can easily get with the UI components available in CS. CS2 may provide better stuff, but I still have to do a lot of work in CS for now.

When you run this, a variable 'doc' automatically points to app.activeDocument, if there is an open document. So you can do something like
Code: Select alldoc.resizeImage(640, 480)
right away from jsh.


A couple of quick notes:
1) Since the command line text is getting 'eval'd inside of a function, you may run into odd scoping issues. You are not natively in the global scope like you would be at the top-level of a script. You will face the same issues with Bridge scripting. The place where this makes the biggest difference is in function definitions. If you use function statements like this:
Code: Select allfunction f() {}
the function is not scoped globally, so it does not exist after that eval. You need to use function literals like this
Code: Select allf = function () {}
to get around the problem.

2) In CS2, you have to be in Step-By-Step mode to see immediate results of anything you type in at the command line. In Accelerated mode, the image won't refresh until you leave jsh.

3) There is a bit of code towards the bottom that trys to preload an external script ("/c/tmp/jshrc.js"). This is a convenient file to drop in stuff like include directives to code that you want to have immediate access to in the interpreter.

4) You can load your own scripts with a normal ''//@include" directive at the prompt.


I've been using this for quite awhile, so it's fairly stable, but do let me know if you run into any problems.

Enjoy.