[texworks] Scripting read access

Stefan Löffler st.loeffler at gmail.com
Sat Dec 4 16:24:00 CET 2010


Hi,

what has been promised for a while is done in a version draft: a
TW.readFile function. Calling it is simple:
res = TW.readFile("path/to/file.txt");

The return value res is a map with one or two properties. res.status
gives you the status code (same as for writeFile). Upon success
(res.status == 0), there's also res.result which contains the text of
the file.
In lua, these things are access the same way. In Python, they are
accessed as a dictionary (res['status']).

There's also a setting for reading in the preferences dialog. By
default, global reading is disabled. Files in the folder containing the
current script (e.g., <resources>/scripts/test/) and its subfolders as
always readable, as are files in the folder containing the current
target (tex/pdf) file's directory, its root file's directory (if
available), and their subfolders.

IMPORTANT NOTE: the workaround so far - namely, using TW.app.openFile -
has been disabled for security reasons. So if your script accesses
files, you will need to change them (slightly).

Also, there's no way anymore to open new windows without the user's
interaction (there's still TW.app.open, but no TW.app.openFile anymore).
I don't consider this particularly important, but if you disagree we may
be able to come up with something that respects permissions...

As always, please test ;).

HTH
Stefan


More information about the texworks mailing list