[texworks] Script: open files in master document \input(myFileName.tex)
Paul A Norman
paul.a.norman at gmail.com
Thu Mar 18 02:37:17 CET 2010
Ok to suppress the OK message box at the end of script execution and
to bring the newly opened document to the forefront, change the end of
the script like this:
var openedFile = TW.app.openFile(currentDirectory + openFileName);
openedFile.show();
} // end if fileName
I was pleasantly surprised to find that TW.app.openFile() returned a
script object referencing the newly opened document, apparently with
the features of a TW.target object.
Paul
On 18 March 2010 13:41, Paul A Norman <paul.a.norman at gmail.com> wrote:
> Hi All,
>
> Hope this may help others -
>
> When using a master document say myMainDoc.tex you often have lots of
> input{} files and it is useful to be able to open these easily, and
> directly sometimes.
>
> If the user highlights a file name in an \input{myFileName.tex}
>
> Assuming that myMainDoc.tex is in the same directory as its 'children
> files' ...
>
> ----------
>
> // TeXworksScript
> // Title: Open Highlighted File Name
> // Description: Opens Highlighted File Name
> // Author: Paul A Norman
> // Version: 0.1
> // Date: 2010-03-18
> // Script-Type: standalone
>
> // Assuming that myMainDoc.tex is in the same directory as its 'children files'
>
> // debugger;
>
> var openFileName = TW.target.selection;
>
> if ((openFileName != '') & (openFileName != null))
> {
>
> // couldn't find a property for current directory for master
> document - work around
> var currentFileName = TW.target.fileName;
>
> if (currentFileName.indexOf("/") > -1) // OS Win and Nix only not
> sure what Mac looks like
> {
> pathSlash = "/";
> }
> else
> {
> pathSlash = "\\";
> }
>
> var currentDirectoryLastDelim = currentFileName.lastIndexOf(pathSlash);
>
> var currentDirectory =
> currentFileName.substr(0,currentDirectoryLastDelim +1)
>
> TW.app.openFile(currentDirectory + openFileName);
>
> } // end if currentFileName
>
More information about the texworks
mailing list