Hi Henrik,<div><br></div><div>Ok there is a more cumbersome 'standard' type approach below, </div><div><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">But if you want complete control form script (and permissions are set)...</span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br></span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">User double clicks </span>\input{filethatdoesnotexist.tex} any where {between} or you get it with TW.target.balanceDelimiters(); then TW,target.selection and remove the braces in script.</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br></span></p>
<p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;">Use TW.target.fileName and extract your file path.</span></font></p>
<p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;"><br></span></font></p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;">Build your full newFileName.</span></font></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="text-align: left; background-color: rgb(255, 255, 255); "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;">Send any contents straight to disk then open the file in an editor window. Contents afaik can be an empty string.</span></font></span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="text-align: left; background-color: rgb(255, 255, 255); "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;"><br>
</span></font></span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="text-align: left; background-color: rgb(255, 255, 255); "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;">Note warnings on html linked page below. ;) s.l.</span></font></span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br></span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span class="rvts28" style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">var resp = TW.writeFile</span><span class="rvts29" style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">(QString filename, QString content);</span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span class="rvts29" style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span class="rvts29" style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">See: </span><a href="http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm?writeFile.html" style="background-color: rgb(255, 255, 255); font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; ">http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm?writeFile.html</a></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br></span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span class="rvts29" style="background-color: rgb(255, 255, 255); font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; ">var opendFileInfo = TW.</span><span class="rvts36" style="background-color: rgb(255, 255, 255); font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; ">app</span><span class="rvts29" style="background-color: rgb(255, 255, 255); font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; ">.</span><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">openFileFromScript( dah dah)</span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br></span></p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">See: </span><a href="http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm?openFileFromScriptQStringintbo.html">http://twscript.paulanorman.com/docs/html/TexWorksQtScripting.htm?openFileFromScriptQStringintbo.html</a></p>
<p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;"><br></span></font></p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;">Note that </span></font><span style="background-color: rgb(255, 255, 255); font-family: Verdana, Geneva, sans-serif; font-size: 15px; ">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)</span></p>
<p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;"><br></span></font></p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;">Hope this helps,</span></font></p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;">Paul -</span></font></p>
<p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;"><br></span></font></p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;"> - a standard ( - low permissions settings) type approach below..</span></font></p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;"><br></span></font></p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; ">Standard type of route below will probably not be much use as you do not have easy full control of the proposed </span><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; ">file name</span><span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; "> 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</span>
</p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><font face="Verdana, Geneva, sans-serif"><span style="font-size: 15px;"><br></span></font></p><p style="text-align: left;margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
</p><div style="text-align: -webkit-auto; "> TW.app.newFile() will give you a new "target" window.document type object ..</div><div style="text-align: -webkit-auto; "><br></div><div style="text-align: -webkit-auto; ">
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "> var xx = TW.app.newFile();</p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "> xx.insertText("hello");</p>
<p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><br></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
//twPan.alert(xx.text);</p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">TW.information(null,"Test", xx.text);</p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<br></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">//Then call </p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><br></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">xx.saveAs();</span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br></span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">Or as it is a first save, just </span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br></span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">xx.save() would works as saveAs()</span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); "><br></span></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<span style="font-family: Verdana, Geneva, sans-serif; font-size: 15px; text-align: left; background-color: rgb(255, 255, 255); ">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.</span></p>
</div><p></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><br></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; "><br></p><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; ">
<br></p><br><div class="gmail_quote">On 4 November 2011 23:38, Henrik Skov Midtiby <span dir="ltr"><<a href="mailto:henrikmidtiby@gmail.com">henrikmidtiby@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi<br>
<br>
I would like to make a script that opens a new file and save it with a<br>
specified name.<br>
<br>
The following approach does not work<br>
TW.app.newFile(newfilename);<br>
<br>
The use case I wan't to handle is the following<br>
A new line with the following content have just been entered<br>
\input{filethatdoesnotexist.tex}<br>
By placing the cursor inside the curly brackets and invoking the<br>
script, texworks should create a new file with the name<br>
"filethatdoesnotexist.tex" in the same directory as the current file.<br>
<br>
Any hints?<br>
<br>
Best regards,<br>
<span class="HOEnZb"><font color="#888888">Henrik<br>
</font></span></blockquote></div><br></div>