Skip to content

Instantly share code, notes, and snippets.

@thundernixon
Last active March 25, 2021 14:48
Show Gist options
  • Save thundernixon/588273076abfee345ad17c21a6b70389 to your computer and use it in GitHub Desktop.
Save thundernixon/588273076abfee345ad17c21a6b70389 to your computer and use it in GitHub Desktop.
Run RoboFont script from VS Code
{
"version": "2.0.0",
"tasks": [
{
"label": "Run in RoboFont",
"type": "shell",
"command": "robofont",
"args": [
"-p",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
@thundernixon
Copy link
Author

thundernixon commented Apr 29, 2019

Run RoboFont script from VS Code

Have you ever wanted to write Python scripts in VS Code and make them execute inside RoboFont?

  1. First, make sure you have installed RoboFont as shell command by going to RoboFont Preferences > Extensions > Shell and click on the install button. To make sure that its installed correctly, run robofont -h in the terminal and hit return. For RoboFont shell command to work correctly you probably need to install PyObjC in terminal using pip3.

  2. In VS Code, open a folder that you wish to run scripts from. This might be a type project, the central RoboFont scripts folder, or somewhere else. VS Code calls this a "workspace," and you can give it specific settings in a .vscode folder.

  3. Use the shortcut command+shift+p to open the Command Palette. Then, search "Tasks: Configure Default Build Task" and select it. Next, select "Create tasks.json file from template," and finally "Other." This will create the file tasks.json in a .vscode workspace folder.

  4. Paste the above tasks.json code in place of the template*.

  5. Now, when you have a Python script in VS Code**, you can hit command+shift+b to instantly run your script in RoboFont.

  6. If you are managing the workspace as a Git project, you should probably add .vscode to your .gitignore file.

* Yes, the version number should be 2.0.0, because it refers to VS Code's task system.

** You need to be working in a saved Python file for this to work. So, start new files by saving them.


Inspired by @typoman's Gist, Robofont.sublime-build

@thundernixon
Copy link
Author

If you wish to bring up the RoboFont Output Window when you run the script (for instance, to view the result of print() statements), update the task's args list to:

"args": [
            "-p",
            "${file}",
            "-c",
            "from mojo.UI import OutputWindow",
            "-c",
            "OutputWindow().show()"
        ],

@eduairet
Copy link

Hi Stephen, I'm attempting to use this command and I'm getting this result:

zsh: parse error near `()'
The terminal process "/bin/zsh '-c', 'robofont -p '/Users/eat/Library/Application Support/RoboFont/scripts/info.py' -c 'from mojo.UI import OutputWindow' -c OutputWindow().show()'" terminated with exit code: 1.

Do you know what does it mean?

Thank you in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment