Python Scripting

Python extends automation beyond a fixed list of Actions. A script can inspect a font, select data according to custom criteria, perform a repetitive edit, or prepare a report that would be awkward to assemble by hand.

Automating FontLab with Python

FontLab includes Python 3.11 for its scripting environment. You do not need a separate system installation merely to run a script inside the application. Older Python 2 or FontLab Studio scripts may require adaptation.

Start with a small task and explicit scope. A script that reads the current selection is easier to review than one that silently modifies every open font. Save the source before running unfamiliar modification code and inspect what it actually changed.

Scripting supports repetitive and bulk work, operations awkward by hand, and third-party tools. This chapter covers the environment rather than teaching Python or listing the complete API; class-by-class reference belongs to developer documentation and Volume Two, with packages introduced in The Python API and Libraries. Use documentation matching the installed FontLab version for object types, arguments, return values, and update/undo requirements.

The Scripting Panel and Console

The Scripting panel follows the panel-opening and focus conventions introduced in Windows, Panels, and Workspaces.

Open Window > Panels > Scripting. The editor holds the current script; the Run control executes it. Printed output and reported errors appear in the Output panel.

The Scripting panel places its script library beside the editor.

The Scripting panel places its script library beside the editor. The displayed TypeRig script is an example of an existing script opened for inspection.

To check the editor-to-output workflow, enter print("FontLab scripting is ready") and click Run. The message should appear in Window > Panels > Output; this example does not change font data.

The py> console supports incremental commands in the scripting context. Variables can persist between runs, so a script may appear to work only because an earlier command created an object it assumes exists.

The local menu provides script New/Open/Save operations and context controls. Clear Python Context resets the namespace before runs when enabled; Clear Python Context Now performs a one-time reset. Clearing output removes the displayed log, not the effects of a script on the font.

Use the search controls to navigate a longer script. In the collapsed panel, the script name and Run access remain useful, but reopen the editor before running a file whose contents or scope you need to review.

Code Editors preferences govern the font, size, indentation, tab width, and wrapping used by the code surfaces. Restart FontLab after changing those global settings. Per-editor Cmd+Plus/Minus on macOS or Ctrl+Plus/Minus on Windows adjusts displayed text size separately; indentation choices distinguish tabs from spaces. A visual indentation setting is not a substitute for correct Python indentation in the file.

The Script Library and File Types

The panel’s library sidebar manages script folders. The Scripts subfolder of FontLab’s user data folder (see The User Data Folder and Customizable Data Files) and registered script folders supply entries in the Script menu, with subfolders organizing related tools. The menu name is singular; the directory name remains plural.

After adding files externally, choose Script > Refresh Scripts or refresh the library. Script > Update / Install Scripts opens extension resources such as TypeRig, discussed in The Python API and Libraries; follow the particular extension’s version and installation instructions. A custom script folder needs to be included in the Scripting panel’s library before its files can appear in the menu.

Choosing a listed script from Script runs it. To inspect a script before execution, open its file in the Scripting panel instead.

Opening a .py file in FontLab loads it in the Scripting panel for editing and manual execution. Opening a .vfpy file executes it immediately without opening that editor. If the operating system associates .vfpy with FontLab, double-clicking the file can therefore run it. Open it in a text editor when you only want to inspect its contents.

Scripts can also enter through supported file-open, drag-and-drop, or command-line routes. Those routes still execute inside the relevant FontLab environment; they do not make a font-modifying script harmless or supply missing font context automatically.

Keep reusable scripts with their purpose, expected selection, supported version, and required packages. A short report of processed glyphs helps confirm the scope after a batch run.