[texworks] Help please with Integer constants and use in messageboxes
Paul A Norman
paul.a.norman at gmail.com
Sun Apr 25 13:37:47 CEST 2010
Dear Jonathan,
Is /config/scripts-library/ ok?
Or would you prefer /config/scripts/scripts-library/
If there is no :-
// TeXworksScript
// Title: dah dah ...
Then such scripts libraries.js would not be read into the Scripts menu
if in /config/scripts/scripts-library/ ?
Revised, removed path delimiter change, moved some variables to global
for reuse in sucessive function calls.
Paul
///////////////////////////// Begin Preamble \\\\\\\\\\\\\\\\\\\\\\\\\
var libraryPath;
var scriptsHere = __FILE__.lastIndexOf("/scripts/");
libraryPath = __FILE__.substr(0,scriptsHere) + "/scripts-library/";
// /script-library/ is a sibling to /scripts/ just below /config/
function getLibrary(libraryName)
{
var thisLibrary = libraryPath + libraryName +".js";
// temporary workaround as their may be a new function "readFile()" available
var libraryOpened = TW.app.openFile(thisLibrary);
var Js = libraryOpened.text;
libraryOpened.close();
libraryOpened = null;
return(Js);
}
// sucessive libaries can be called this way.
eval(getLibrary("const_hello"));
eval(getLibrary("const_second"));
eval(getLibrary("functions_messages"));
///////////////////////////// End Preamble \\\\\\\\\\\\\\\\\\\\\\\\\
Paul
On 25 April 2010 23:19, Paul A Norman <paul.a.norman at gmail.com> wrote:
> On 25 April 2010 21:24, Jonathan Kew <jfkthame at googlemail.com> wrote:
>> It's pretty neat that this works;
>
> Could write wrappers and other re-usable Tw specifc helper functions
> in Libraries
>
>>however, I think we should expose a readFile() method to directly read the text of a file, rather than going through the "open document, get text, close document" sequence. That's pretty inefficient, and could become a significant overhead if you were loading a number of script libraries.
>
> readFile() would be really helpful for other things as well.
>
>>
>> I'm curious whether this:
>>
>>> thisLibrary = thisLibrary.replace(/\//g, '\\'); //MS Windows Specific
>>
>> is actually needed? Many programs and functions on Windows will accept either \ or / as path separators; did you try it without this conversion?
>
> Thanks Jonathan, I started using that in early scripts (earlier Tw
> vers) when it threw a message box (and an exception I think) saying
> "Can not read file "dah dah": No such file or directory", and that
> fixed the problem, but I just rem-ed it out and it is not necessary at
> all now (windows Xp) it seems (Tw ver 0.3 r606).
>
>>
>> JK
>>
>>
>>
>>
>
More information about the texworks
mailing list