[texworks] Scripting read access
st.loeffler at gmail.com
Sun Dec 5 13:48:05 CET 2010
On 2010-12-04 23:16, Paul A Norman wrote:
> I have been using the fileOpen functions to open all sub documents
> when using a master document, there's been a script up on your script
> Issues page for quite a few months now.
Now you mention it, yeah, I remember dimly ;).
> Its sort of useful especially when you need to search through all
> documents - they all need to be open before the search starts. Or when
> you just want to position the cursor and open a sub document. (Select
> between braces, get selected text, construct full path, open document)
> If the user has allowed scripts to read documents from disk - could
> we make these script functions for actually opening Tw documents work
> on the same User's check box preference selection? Perhaps
> automatically allowing same target and script and sub directories as
> for the readFile function itself?
> There would be other times when it is very useful to be able to open
> Tw document(s) from script for user editing.
> Be sad to loose this functionality.
OK, in r709, I've reinstated a method named openFileFromScript. Typical
usage would be:
res = TW.app.openFileFromScript("/path/to/file.tex", TW, -1, true);
The behavior is very similar to readFile, w.r.t. the handling of
relative paths and required permissions. res also is similar to the
return value of readFile, only res.result is now the object of the
opened window (if any). The second parameter (TW) is required to give
the function the proper context. The last two arguments are optional. -1
is the line number (the default -1 stands for the start of the file),
and true is whether or not to ask the user for permission to open the
file in case the "normal" permissions are insufficient.
> Or allow ALL things of this perceived security issue nature to be
> doable if "use script plugins" is ticked by the User, as after all
> the script plugins automatically open the Pandora's box of security
> issues wide open any way don't they?
Well, there are several connections between the different security
settings. E.g., with execution enabled, you can possibly read and write
files with `cat path/to/file` or `echo "Content" > path/to/file`. Also,
as you say, plugins may bypass these protected functions of Tw
altogether. Nevertheless, I don't think this should be encouraged.
> It would seem counter intuitive that read or write scripts be turned
> off, and script plugins be
> turned on letting python and Lua then do things that QtScript can then
> not do - seems confusing?
Well, the read, write, execute permissions naturally only apply to Tw.
What a scripting plugin may or may not do in addition, and how it
enforces any of these restrictions, is up to the plugin. That's why
plugins are powerful, but dangerous, and are hence disabled by default.
Note, though, that I haven't heard many accounts of non-QtScript scripts
lately... so the question is how much the "enable plugins" option will
be used at all.
More information about the texworks