[texworks] SCRIPTING: Get content of specified directory

Henrik Skov Midtiby henrikmidtiby at gmail.com
Mon May 16 17:53:17 CEST 2011


Hi Paul

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
http://code.google.com/p/texworks/issues/detail?id=261#c60
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.
====================

Best regards,
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.
> http://twscript.paulanorman.com/docs/html/files/systemQString.html
>
> (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
>
> http://twscript.paulanorman.com/docs/html/files/getOpenFileNames.html
>
> See also notes in
> http://twscript.paulanorman.com/docs/html/files/getOpenFileNameQString.html
>
> Can get one or multi-select more file names though returns an array in
> that case, requires User interaction though.
>
> Paul
>
>
>
> On 15 May 2011 21:26, Henrik Skov Midtiby <henrikmidtiby at gmail.com> wrote:
>> Hi
>>
>> >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 mailing list