[texworks] Scripting: Open new file with a specified name

Paul A Norman paul.a.norman at gmail.com
Fri Nov 11 11:34:24 CET 2011


Thanks Henrik,

Great work, I have replaced comments 13 and 14 on issue 261 with this
note http://code.google.com/p/texworks/issues/detail?id=261#c70

Paul

On 11 November 2011 22:54, Henrik Skov Midtiby <henrikmidtiby at gmail.com> wrote:
> Thanks for the input.
>
> I have taken the freedom to update the openAllinputs-tex.js script.
> If the script tries to open a non existent file, a new file with the
> requested file name is created (provided that the needed permissions
> are set). The new file is populated with lines from the current
> document that contains the string "% !TEX", such that information
> about root document, spell checking and latex program is passed on.
>
> Check out the script at
> https://github.com/henrikmidtiby/autocompleteForTexworks/blob/master/scripts/openAllinputs-tex.js
>
> Best regards,
> Henrik
>
> On 5 November 2011 00:05, Paul A Norman <paul.a.norman at gmail.com> wrote:
>> Hi Henrik,
>> Ok there is a more cumbersome 'standard' type approach below,
>>
>> But if you want complete control form script (and permissions are set)...
>>
>> User double clicks \input{filethatdoesnotexist.tex} any where {between} or
>> you get it with TW.target.balanceDelimiters(); then TW,target.selection and
>> remove the braces in script.
>>
>> Use TW.target.fileName and extract your file path.
>>
>> Build your full newFileName.
>>
>> Send any contents straight to disk then open the file in an editor
>> window. Contents afaik can be an empty string.
>>
>> Note warnings on html linked page below.   ;)  s.l.
>>
>> var resp = TW.writeFile(QString filename, QString content);
>>
>> See: http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm?writeFile.html
>>
>> var opendFileInfo = TW.app.openFileFromScript( dah dah)
>>
>> See: http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm?openFileFromScriptQStringintbo.html
>>
>> Note that opendFileInfo is an object with a member result which points to a
>> target object for the newly opened file which you can use as if it were
>> TW.target  (see link above for more  details)
>>
>> Hope this helps,
>>
>> Paul -
>>
>>  - a standard ( - low permissions settings) type approach below..
>>
>> Standard type of route below will probably not be much use as you do not
>> have easy full control of the proposed file name in Script, you could build
>> it from the selection property, and the filepath of the current document,
>> and put it on the clipboard using the clipboard property, and then manually
>> paste it into the SaveAs dialogue box when it appears
>>
>>  TW.app.newFile() will give you a new "target" window.document type object
>> ..
>>
>>  var xx = TW.app.newFile();
>>
>>       xx.insertText("hello");
>>
>> //twPan.alert(xx.text);
>>
>> TW.information(null,"Test", xx.text);
>>
>> //Then call
>>
>> xx.saveAs();
>>
>> Or as it is a first save, just
>>
>> xx.save() would works as saveAs()
>>
>> As far as I know so far, you can not pass anything useful by way of a file
>> name to .saveAs()  -- .saveAs("myFile")   - string is ignored.
>>
>>
>>
>> On 4 November 2011 23:38, Henrik Skov Midtiby <henrikmidtiby at gmail.com>
>> wrote:
>>>
>>> Hi
>>>
>>> I would like to make a script that opens a new file and save it with a
>>> specified name.
>>>
>>> The following approach does not work
>>> TW.app.newFile(newfilename);
>>>
>>> The use case I wan't to handle is the following
>>> A new line with the following content have just been entered
>>> \input{filethatdoesnotexist.tex}
>>> By placing the cursor inside the curly brackets and invoking the
>>> script, texworks should create a new file with the name
>>> "filethatdoesnotexist.tex" in the same directory as the current file.
>>>
>>> Any hints?
>>>
>>> Best regards,
>>> Henrik
>>
>>
>
>



More information about the texworks mailing list