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

Paul A Norman paul.a.norman at gmail.com
Sun Dec 19 10:34:40 CET 2010


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.

In my preferences, TeXworks is set to open a new file when the
application starts.

This script (below) however does not execute  when the application
starts. Is that perhaps to do with the way the application
initialises, and doesn't open the NewFile the same way as the menu
command would do it later, if used by the User?

Was planning to rely on this for initialisation purposes.

Would it be difficult to run in a hook for ApplicationReady
Or would that be after 0.4?


... This does work ok with File/New or Crtl+N, but not when the
application starts and presnts a NewFile to the User.

// TeXworksScript
// Title: Load Globals
// Description: Preloads gloabal varibales used in script modules
// Author: Paul A Norman
// Version: 0.3
// Date: 2010-12-19
// Script-Type: hook
// Hook: NewFile

TW.information(null,"Hello","Hello from NewFile Hook");

/* The rest not needed for testing purposes

   if (TW.app.hasGlobal("pan_Tw") == false)
       var pan_tw = TW.readFile("pan_Tw.mod");

       TW.app.setGlobal("pan_Tw", pan_tw.result) // makes it available
for later eval() in other scripts
                                          // eval() of this will
create: twConst, msgBox, twPan, global_load(globalName),


   if (TW.app.hasGlobal("phpjs_namespaced") == false)
       var phpjs_namespaced = TW.readFile("phpjs.namespaced.mod");
       TW.app.setGlobal("phpjs_namespaced", phpjs_namespaced.result)
// makes it available for later creation in other scripts

   if (TW.app.hasGlobal("helper_php_js") == false)
       var helper_php_js = TW.readFile('helper_php_js.mod');
       TW.app.setGlobal("helper_php_js", helper_php_js.result) //
makes it available for later eval() in other scripts


More information about the texworks mailing list