[texworks] SCRIPTING: Get content of specified directory
Henrik Skov Midtiby
henrikmidtiby at gmail.com
Mon May 16 17:53:17 CEST 2011
Thanks for your input.
I now have autocompletion working for the macros \includegraphics,
\input and \include based on the files present in the directory of the
file open for editing.
This part works on systems where the "ls" command is available and
where the file path does not contain any spaces. The code have only
been tested on linux at the moment.
The result is uploaded at
With the description
Context based autocompleter for completing words used in the open
document, arguments to label and ref and as a new feature filename
autocompletion for include, input and includegraphics commands.
Guide to use.
1. start typing the long word that should be autocompleted
2. press "<crtl> + m" and the autocompleter will complete the word or
at least make a suggestion for a completion.
3. if not satisfied with the suggestion press "<crtl> + m" until the
correct word is found.
Henrik Skov Midtiby
On 15 May 2011 12:22, Paul A Norman <paul.a.norman at gmail.com> wrote:
> Dear Henrik,
> Not so far as far as I know.
> As you have, I've been using system calls to things like "cmd /c
> mkdir \""+ documentPath +"images\""
> Can switch case on
> http://twscript.paulanorman.com/docs/html/files/platform.html and
> prepare differnt statements for the TW.system call.
> (see subheadngs in and under main headings "User 'Library' Modules and
> helper objects" at
> http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm for
> some explanation on twPan - recomend downloading from
> http://twscript.paulanorman.com/docs/index.html and the .chm there.)
> and have been using things like ...
> function chooseFromDirectoryListing(Description, pathDir, fileExtension)
> // pathDir (no trailing slash), fileExtension with . E.g. .txt
> // TW.app.clipboard = "cmd /c dir /b \""
> + pathDir + "\\*" + fileExtension + "\"";
> var fileList = twPan.osCmd("cmd /c dir /b \""
> + pathDir + "\\*" + fileExtension + "\""
> , true)
> removeExtnsn = new RegExp(fileExtension,"ig");
> fileList = fileList.replace(removeExtnsn,"").split(lineBreak);
> // var chosenAnswer =
> // twPan.select(Description, fileList);
> var chosenAnswer = TW.getItem(null, Description, Description, fileList);
> if (twPan.emptyString(chosenAnswer) == false)
> chosenAnswer = chosenAnswer + fileExtension;
> return chosenAnswer;
> You can use
> See also notes in
> Can get one or multi-select more file names though returns an array in
> that case, requires User interaction though.
> On 15 May 2011 21:26, Henrik Skov Midtiby <henrikmidtiby at gmail.com> wrote:
>> >From at script would I like to get access to the contents of the
>> current directory.
>> This information should be used for autocompleting filenames for
>> includegraphics and input macros in latex.
>> I know it is possible to access the commandline and issue an 'ls -all'
>> or something similar, but is this information also available directly
>> in QtScript?
>> Best regards,
>> Henrik Skov Midtiby
More information about the texworks