Scripting

» Scripting can help with a lot of repetitive tasks. You can access all the internal data and methods. This is done with the help of the PyobjC bridge and convenience wrappers. Support is available for Robofab

Documentation

Core Reference 0.2

Documentation of the internal object structure.

Python API Documentation

Documentation of the Python wrapper. GlyphsApp module translates the most features to be accessible in a python like way.

Installing Robofab

To install Robofab, Download the latest version from robofab.org.
The file “RoboFab491M_plusDependencies.zip” (as of this writing. The version number might be higher.) contains four folders “DialogKit”, “FontTools”, “RoboFab” and “Vanilla”. Each contains a “Lib” folder with one subfolder. Copy this subfolder to: “/Library/Python/2.5/site-packages/”.

Adding Scripts

There are two ways to use scripts. You can use the internal macro panel [see below] or “install” them in the scripts folder and access them from the scripts menu.

You can find a list of already available scripts in Github. To access them, download and place them in the folder:

/Users/[your user folder]/Library/Application Support/Glyphs/Scripts

You can access this folder from within Glyphs by choosing Script > Open Script Folder. To reload the scripts menu, hold down the Option key while opening the Scripts Menu and click Reload Scripts.

Integrated Macro Panel

The second way to use scripts is through the Integrated Macro Panel.

This is only a very small example but shows the basics.
It gets the fist Master of the glyph “a”, prints all nodes and moves them around.

  • # two way to access Layers in a Glyph
  • # The first is with the FontMaster ID
  • FontMaster = Font.masters[0]
  • Layer = Font.glyphs["A"].layers[FontMaster.id]
  • # Or with the index of the layer:
  • Layer = Font.glyphs["A"].layers[0]
  • print Layer
  • for currPath in Layer.paths:
  • if currPath.closed:
  • print “closed Path”
  • for currNode in currPath.nodes:
  • # setting the coodinates for a node with a Point
  • Position = currNode.position
  • Position.x = Position.x + 10.5
  • Position.y = Position.y – 10.5
  • currNode.position = Position
  • # or with setting the x or y values directly.
  • currNode.x = currNode.x – 100

Internal Structure & Debugging

To have a look at the internal structure and for debugging, it might be useful to have a look at the wrapper module itself.

You can find it in the Glyphs bundle at

Glyphs.app/Contents/Scripts/GlyphsApp.py