How running silently a script (e.g. with no window creation/swap/activation/...)

How running silently a script (e.g. with no window creation/swap/activation/...)

2
NewbieNewbie
2

    Oct 15, 2012#1

    Hi!
    Using UltraEdit (v18.20) JavaScript scripting (very nice feature) and launching my script on a file directory content so on several hundreds files, I want to run my script silently i.e. without opening a new UltraEdit thumb nailed window for each file.

    Today, for each file, I open the file so a new associated window opens, the script works on the content of the file (E.g. re-indent of it), so I save and close the modified file.

    I'll hope a method like "UltraEdit.activeDocument.close(Force/Normal/...)" but I hadn't found it, is it exist? Today, if my directory contents 150 files, at the end of the script execution, I'll obtain 150 windows in UltraEdit env!!!

    Or better, a feature (toggle?) witch allows the script to run silently i.e. without creating any window or swap/activation between several windows, a possible evolution of UltraEdit ? (it exists in JS under MS Excel and it is useful and clearly less horsepower and time consuming).
    Regards
    Goulou910

    6,682583
    Grand MasterGrand Master
    6,682583

      Re: How running silently a script (e.g. with no window creation/swap/activation/

      Oct 16, 2012#2

      As you can read in announcement topic JavaScript tutorial, power tips and more the help page with title Scripting commands best opened via Index tab of help lists all UltraEdit scripting commands. Not included on this help page are the Javascript core objects with their methods and properties.

      You can also open View - Views/Lists - Tag List and select tag group UE/UES Script Commands. There are 3 file closing commands listed:
      • File close with prompt
      • File close with saving
      • File close without saving
      Double click on File close with saving and the command

      UltraEdit.closeFile(UltraEdit.activeDocument.path,1);

      is inserted into active file which closes on script execution the active file with saving it before.

      There is no option to run scripts silently or without updating the display if the commands are executed on active file. If you run a script which reformats a bunch of files, and you want in the meantime continue your work with UltraEdit, you can either
      • start a second instance of UltraEdit via Advanced - Open New Instance of UltraEdit, start the script and minimize the UE window running the script, switch to first UltraEdit instance and work with it while the second instance of UE is executing the script, or
      • start a second instance of UltraEdit via command line with the script to execute also entered on command line. Something like
        "Program files directory of UltraEdit\uedit32.exe" /fni /s,e="full path to script file"
        The help page with title Command Line Parameters contains the explanation of all available command line parameters supported by UltraEdit. Minimize the opened UE window after start so that you can continue your work in other applications like an already running instance of UltraEdit.

      2
      NewbieNewbie
      2

        Oct 16, 2012#3

        Hi Mofi, hi all,
        @Mofi, Many thanks for your quick and rich answer responding in different ways to my question ! Your proposal to use 'UltraEdit.closeFile(UltraEdit.activeDocument.path, n);' with n equals to 0, 1 or 2 is very interesting because it closes effectively the UltraEdit.activeDocument window even the 'UltraEdit.activeDocument.path' value does not respect the rule indicating that this path string must use double backslash separators and must start and finish with quotes as said in the help.
        fileNameToOpen = UltraEdit.activeDocument.path;
        fileNameToClose = fileNameToOpen.replace(/\\/g,"\\\\"); // to double each backslash
        UltraEdit.open("\""+fileNameToOpen+"\""); --> OK, it's normal it is the API format
        or
        UltraEdit.open(fileNameToOpen); // without quotes --> OK !!! Help (F1 key) says that file name must be between quotes
        then in the following tests, we obtain:
        UltraEdit.closeFile("\""+fileNameToClose+"\"", 1); --> NotOK !!! why? It is the API format...
        UltraEdit.closeFile(fileNameToClose, 1); --> NotOK, normal because no quotes
        UltraEdit.closeFile("\""+fileNameToOpen+"\"", 1); --> NotOK, normal because no double backslashes
        UltraEdit.closeFile(fileNameToOpen, 1); --> OK !!! Not normal because backslashes are not doubled
        UltraEdit.closeFile(UltraEdit.activeDocument.path, 1); --> OK !!! Not normal because no quote nor double backslashes

        May be a bug...
        In any way, thanks ;-)
        Best regards
        Goulou910

        6,682583
        Grand MasterGrand Master
        6,682583

          Oct 16, 2012#4

          There is a misunderstanding. The help is right.

          The parameter of command UltraEdit.open() and the first parameter of UltraEdit.closeFile() must be a string value. So here comes a Javascript for beginners lesson.

          A string is defined in Javascript with:
          • text enclosed in straight double quotes " - a straight single quote character ' within the text must not be escaped with a backslash, or
          • text enclosed in straight single quotes ' - a straight double quote character " within the text must not be escaped with a backslash.
          The backslash \ has a special meaning in Javascript strings. It is the escape character for special characters like \t for a horizontal tab, \r for a carriage return, \n for a line-feed, ... It is necessary to write 2 backslashes \\ to inform the Javascript interpreter that the string should contain the backslash character itself.

          Some examples:

          For opening file C:\temp\test.txt: UltraEdit.open("C:\\temp\\test.txt");

          For opening file C:\temp\test'1.txt: UltraEdit.open("C:\\temp\\test'1.txt");
          Single quote characters are allowed in file names on Windows file systems.

          For opening file C:\temp\test'1.txt: UltraEdit.open('C:\\temp\\test\'1.txt');
          If single quote characters are used to define the string value, a single quote character inside the string value must be escaped with a backslash.

          A file name cannot contain a straight double quote character. So there is no reason to use single quotes to define the file name string value without the need to escape a straight double quote character. Such a string value definition with single quotes makes sense for example in a search or replace string like

          UltraEdit.activeDocument.findReplace.replace('<a href="www.ultraedit.com"', '<a href="www.idmcomp.com"');

          The same command with using straight double quotes for string value definition is:

          UltraEdit.activeDocument.findReplace.replace("<a href=\"www.ultraedit.com\"", "<a href=\"www.idmcomp.com\"");

          Now we take a look on some wrongly defined file name string values.

          For opening file C:\temp\test.txt: UltraEdit.open("C:\temp\test.txt");
          That command produces an error message because the Javascript interpreter passed to command UltraEdit.open() the string C:tabemptabest.txt and such a file does surely not exist.

          For opening file C:\temp\test.txt: UltraEdit.open(C:\\temp\\test.txt); or UltraEdit.open(C:\temp\test.txt);
          Both commands results in syntax error message on script start reported by Javascript interpreter captured by UltraEdit and written to output window. The 2 strings are not valid strings as not enclosed in double or single quotes, but are at same time also invalid names for a variable.

          Instead of passing a fixed string value defined directly in the file opening or closing command, it is of course also possible to call the commands with a variable already holding the file name. UltraEdit.activeDocument.path is such a string variable. path is member variable (property) of type string of class (object) activeDocument which is again a member variable of class UltraEdit.

          So you can use also

          var sFileName = "C:\\temp\\test.txt";
          UltraEdit.open(sFileName);


          Or if there is currently a file name selected in active file

          UltraEdit.open(UltraEdit.activeDocument.selection);