[texworks] SCRIPTING: readFile() xxxGlobal() and NewFile hook

Paul A Norman paul.a.norman at gmail.com
Mon Dec 20 03:42:00 CET 2010


Thanks for sorting through that hook issue guys,

On 20 December 2010 08:36, Stefan Löffler <st.loeffler at gmail.com> wrote:
> Hi,
>
> On 2010-12-19 15:00, Jonathan Kew wrote:
>> On 19 Dec 2010, at 09:34, Paul A Norman wrote
>>> First, TW.readFile() is working really nicely so far thank you. Yet to
>>> try for  paths outside document and script's directory trees. Working
>>> with default settings first.
>>> Returning an object for inspection from the readFile() call, works as
>>> a nice clean design solution when all things are considered - well
>>> done I reckon Stefan!
>>>
>>> Haven't worked with writeFile() yet.
>>>
>>> And TW.app.xxxGlobal("xXx") are all working nicely! Haven't tried
>>> TW.script versions yet.
>
> Thanks for letting us know - it sounds good.

Seems TW.app.setGlobal("xxx",Xxx);  just nicely overwrites itself if
called again (an update), any possible issues with calling it
identically in same session please?

Some interesting possibilities open up for simplifying scripting ...

//TeXworksScript
//Title:  Experimental TW
//Description: Exploration of TW objects
//Author:  Paul A. Norman
//Version: 0.3
//Date:  2010-12-20
//Script-Type: standalone
//Context: TeXDocument
//Shortcut: Alt+T, Alt+W

    with(TW.app)
    {
     // Begin - *with* TW.app

     eval(getGlobal("pan_Tw"));
     // using longhand so that libraries can be independently loaded

     eval(getGlobal("helper_php_js"));
    // using longhand so that libraries can be independently loaded

     // End. - *with* TW.app
    }

    with(twPan) with(PhpJs) with(TW.app) with(TW.target)
     // While carefully using judicious function naming ...
    {
    // Begin - *with* TwScript / library objects

     alert( chr(84) + chr(119) + chr(83) + chr(99) + chr(114) +
chr(105) + chr(112) + chr(116));

     alert(text); // presents TW.target.text


    var fileNamesArray = getOpenFileNames(); // TW.app.getOpenFileNames()

    if (fileNamesArray.length > 0)
      {
       alert(fileNamesArray[0]);
       }
      else
       {
         alert('No File(s) chosen');
         }


     // End. - *with*  TwScript / library objects
     }

 //       twPan.insertGraphics();



More information about the texworks mailing list