Skip to main content
Vamitul
Legend
June 20, 2012
Question

Indesign command box

i often need to run some very simple scripts (one-line, maby 2) and opening the ESTK just for the console.. seems wrong.

I'we made this script to be able to run simple comands just like that form a panel.

also, i'we predefined some variables for convenience:

doc=app.activeDocument

sel=app.activeDocument.selection[0]

Multiline mode not working for now(the edittext controls make me wanna scream), but the command box accepts multiple commands separated by a comma

questions:

other useful variables to preinitialize?

a hassle-free way of getting multiline to work?

a easy to implement a history of recent run commands?

#targetengine "session";

var win = new Window("palette", "CommandBOX", undefined, {resizeable: true, });

with(win){

          win.topGrup = add( "group", undefined, undefined );

          win.topGrup.alignment = ['fill', 'fill'];

          win.topGrup.alignChildren = ['fill', 'fill'];

          win.topGrup.minimumSize = [250,100];

          with(win.topGrup){

                    win.topGrup.resultPanel = add( "panel", undefined, 'Result:', {borderStyle: 'sunken', } );

                    win.topGrup.resultPanel.alignChildren = ['fill', 'fill'];

                    win.topGrup.resultPanel.minimumSize = [200,80];

                    with(win.topGrup.resultPanel){

                              win.topGrup.resultPanel.ResultText = add( "edittext", undefined, undefined, {readonly: 'true', multiline: 'true', } );

              win.topGrup.resultPanel.ResultText.text=app.extractLabel("cmdBox_result");

            }

                    win.topGrup.controlP = add( "panel", undefined, undefined );

                    win.topGrup.controlP.alignment = ['right', 'fill'];

                    with(win.topGrup.controlP){

            win.topGrup.controlP.buttonGrup = add( "group", undefined, undefined );

                with(win.topGrup.controlP.buttonGrup){

                                        win.topGrup.controlP.buttonGrup.butClear = add( "iconbutton", undefined, undefined, {style: 'toolbutton', } );

                                        win.topGrup.controlP.buttonGrup.butClear.image = ScriptUI.newImage("C:/Program Files (x86)/Adobe/Adobe InDesign CS5/Plug-Ins/Graphics/(DynamicDocumentsUI Resources)/idrc_PNGR/21300.idrc");

                                        win.topGrup.controlP.buttonGrup.butClear.helpTip = "Clear Results";

                                        win.topGrup.controlP.buttonGrup.butHelp = add( "iconbutton", undefined, undefined, {style: 'toolbutton', } );

                                        win.topGrup.controlP.buttonGrup.butHelp.alignment = ['right', 'center'];

                                        win.topGrup.controlP.buttonGrup.butHelp.image = ScriptUI.newImage("C:/Program Files (x86)/Adobe/Adobe InDesign CS5/Plug-Ins/Layout/(Info Panel Resources)/idrc_PNGR/5110.idrc");

                                        win.topGrup.controlP.buttonGrup.butHelp.helpTip = "Help";

                                        }

             win.topGrup.controlP.butRun = add( "button", undefined, 'Run!' );

             win.topGrup.controlP.butRun.shortcutKey = "Enter";

             win.topGrup.controlP.MultiBox = add( "checkbox", undefined, 'Multiline:' );

                              }

                    }

          win.commandP = add( "panel", undefined, 'Command:' );

          win.commandP.alignment = ['fill', 'fill'];

          win.commandP.minimumSize = [250,100];

          with(win.commandP){

                    win.commandP.commandText = add( "edittext", undefined, undefined );

                    win.commandP.commandText.alignment = ['fill', 'fill'];

        win.commandP.commandText.text=app.extractLabel("cmdBox_command");

                    }

          }

win.onResizing = function(){ this.layout.resize() }

win.onShow = function(){ this.layout.layout(); this.minimumSize = this.preferredSize }

win.onClose=function(){

    app.insertLabel("cmdBox_command",win.commandP.commandText.text);

    app.insertLabel("cmdBox_result",win.topGrup.resultPanel.ResultText.text);}

win.topGrup.resultPanel.ResultText.onChange = function(){

          }

win.topGrup.controlP.buttonGrup.butHelp.onClick = function(){ alert("Predefined variables for convenience:\rdoc=app.activeDocument\rsel=app.activeDocument.selection[0]\r\rMultiline mode not working for now, \rbut the command mox accespts multiple commands\rseparated by \";\"","Help");

          }

win.topGrup.controlP.buttonGrup.butClear.onClick = function(){win.topGrup.resultPanel.ResultText.text='';}

win.topGrup.controlP.butRun.onClick = function(){

//uselful variables

var doc=app.activeDocument;

var sel=doc.selection[0];

    try {

win.topGrup.resultPanel.ResultText.text=app.doScript(win.commandP.commandText.text,undefined,undefined,UndoModes.entireScript,'CommandBox')+'\r'+win.topGrup.resultPanel.ResultText.text; 

}

catch (e) {win.topGrup.resultPanel.ResultText.text="****"+'\r'+e.message + "\r(line " + e.line + ")\r****\r"+win.topGrup.resultPanel.ResultText.text

     alert (e.message + "\r(line " + e.line + ")")};

          }

win.topGrup.controlP.MultiBox.onClick = function(){

    win.commandP.commandText.multiline=win.topGrup.controlP.MultiBox.value;

win.topGrup.resultPanel.ResultText.text='Multiline mode '+String(win.commandP.commandText.multiline)+'\r'+win.topGrup.resultPanel.ResultText.text;

    }

win.center();

win.show();

This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

bduffy323
Inspiring
June 20, 2012

For starters you have an extra comma after multiline:'true'

your code : win.topGrup.resultPanel.ResultText = add( "edittext", undefined, undefined, {readonly: 'true', multiline: 'true', } );

correct code: win.topGrup.resultPanel.ResultText = add( "edittext", undefined, undefined, {readonly: 'true', multiline: 'true' } );

That made the multiline work for me in your results box. I didn't look into making the checkbox work though . Hope that helps!

Translate