CodeMenu is a handy snippet manager for macOS - and one of its neat features is the ability to run snippets. Out of the box it runs JavaScript, but it’s flexible: you can teach CodeMenu to run almost any language by pointing it at the right command-line utility or script. This short guide shows two simple examples (Python and C) so you can add languages quickly.

How CodeMenu runs snippets

CodeMenu executes snippets by writing the snippet to a temporary file and invoking the language runner you configured for that language. The runner can be a simple interpreter (for languages like Python or Ruby) or a small shell script that compiles and executes code (for C, C++, etc.). The snippet’s stdout is captured and shown as the snippet output.

Because CodeMenu runs user-specified binaries from a restricted location, you have to link the utilities you want to allow into CodeMenu’s utilities directory - this keeps execution safe and discoverable.


Example 1 - Add Python (using python3)

If you already have python3 installed, adding it is straightforward.

  1. Open a terminal and change to CodeMenu’s application scripts directory:
1
cd ~/Library/Application\ Scripts/id.thedev.marcin.CodeMenu
  1. Create a symbolic link to the interpreter (this makes the binary visible to CodeMenu):
1
ln -s "$(which python3)" .

You can replace $(which python3) with an absolute path if you prefer.

Linking python3 to CodeMenu utilities

  1. Open CodeMenu → Preferences → Code execution. Click + Add, choose a Language (e.g. Python) and set the Language runner to python3 (it will show the name of the file you linked). Save the language.

Code execution settings

Now a snippet saved with the Python language will be written to a temp file and executed with python3 temp_file.py, and its output will be captured by CodeMenu.


Example 2 - Add C (using clang)

Compiled languages usually need a tiny wrapper to compile and run the temporary file. You can add such a wrapper as a runner script.

  1. Return to the utilities directory:
1
cd ~/Library/Application\ Scripts/id.thedev.marcin.CodeMenu
  1. Create a runner script (example clang_run.sh) with the following contents:
1
2
3
4
5
6
7
#!/bin/zsh

# $1 is the path to the temporary source file provided by CodeMenu
clang -o /var/tmp/compiled_app "$1"
chmod +x /var/tmp/compiled_app
/var/tmp/compiled_app
rm /var/tmp/compiled_app

This script compiles the temporary source file to /var/tmp/compiled_app, runs it, then removes the binary. Adjust the paths or flags if you need additional options (e.g. -O2, -Wall, or linking libraries).

  1. Make the script executable:
1
chmod +x clang_run.sh
  1. In CodeMenu → Preferences → Code execution, add a new language entry, select the clang_run.sh script as the Language runner, and name the language (e.g. C). Save.

Now when you run a C snippet, CodeMenu will call your script and capture the program output.


Tips and safety notes

  • Keep runners in the special application scripts directory so CodeMenu can control what executes. Don’t symlink random user binaries from untrusted locations.
  • For interpreted languages, prefer pointing to an interpreter (python3, ruby, node) that reads the temp file and prints result to stdout.
  • For compiled languages, write a small wrapper script that compiles to a temp location and runs the binary; make sure to clean up temporary files.
  • If a runner needs extra libraries or environment variables, either embed them in the script or use a wrapper that sets those values before invoking the compiler/interpreter.

That’s it - with these steps you can add new languages to CodeMenu and run snippets right from the app. If you’d like, I can add examples for other languages (Node, Ruby, Swift) or draft a small, shareable runner script template you can drop into the utilities folder.

Thanks for reading - enjoy running code with CodeMenu!