Starting a Script

Parent Previous Next

Using/Running  Scripts


As we saw in the last picture there are two main types of scripts, with a third called libraries on the drawing board as well.


The two types we are concerned with here are "Standalone Scripts" and "Hooks".


Unless unticked in the Script Manager, standalone scripts attach themselves to the Tw Scripts menu according to their Title.


Lets look again at the debugger script. That will cause the debugger to show:-


// TeXworksScript

This first line tells Tw  that this script is a QtScript not Python, Lua or anything else.


// Title: &Debug

This is the title that will appear on the Tw script menu The ampersand "&" indicates what letter would have an underline under it and so also be available as an Alt short cut key.


// Description: Starts the Debugger

This description will show in the Script Manager and might in a future release of Tw also show as a mouse over in the Scirpt menu. (http://code.google.com/p/texworks/issues/detail?id=17&q=hint#c17)


// Author: Jonathan Kew

As stated


// Version: 0.1

...


// Date: 2010-03-18

...


// Script-Type: standalone

This means that the user has to start the script, it will not be automatically started by Tw say when the Type Setting finishes, automatically started scripts are called hook scripts.


// Context: TeXDocument

If written in here (optional) this means that the script it can appear in the Scripts menu in an editor window, but won't appear in the PDF preview windows' Script menus.


// Shortcut: Alt+S, Alt+D

Keyboard shortcuts that can be used to start the script.


debugger;

Our command in QtScript.  This is not a Tw api or QtScript command so it literally starts the debugger to tell you an error has happened.



Once this is saved, in my case in scripts/Scripting - Experiments/debugger.js


... and the Script List has been "Reloaded",

or the programme has been restarted,

then we can run it from the menu, or use its short cut keys (if some were added) from the key board.



To use the short keys, on Windows, holding down the Alt Key, tap the S and then the D key(s) before releasing the Alt Key.


Created with the Personal Edition of HelpNDoc: Easily create CHM Help documents