PhonShell

PhonShell is an interactive scripting console associated with the Phon window from which it was opened. Open it with Tools > PhonShell. When opened from a project or Session Editor window, scripts can work with that window's project or session context.

The scripting languages and filename extensions available to the shell are determined by the script engines installed with Phon. The full application includes JavaScript and Groovy support.


PhonShell Window

Warning: PhonShell scripts run with the same file and application access as Phon. Run only scripts you trust, and save important project data before executing a script that changes it.

Run commands and scripts

Enter a statement at the prompt and press Enter. The prompt identifies the active script engine.

To execute a script file, use one of these methods:

  • Select File > Run script... in the PhonShell window and choose a file supported by an installed script engine. Output is sent to a Phon buffer named for the script file.

  • Drag a supported script file onto the console.

  • Enter ::exec followed by the script path:

    ::exec "/path/to/script.js"

The shell provides a window variable for the Phon window that opened it. The exact object and available project or session data depend on that parent window.

Send output to a buffer

Append > name to a statement to send its output to a Phon buffer. If the buffer already exists, its contents are replaced.

out.println("First result"); > results

Use >> name to append output instead. Phon creates the buffer if it does not exist.

out.println("Another result"); >> results

Buffer names must begin with a letter and can contain letters, numbers, hyphens, and periods.

Make scripts available from the Tools menu

The Tools > PhonShell scripts menu lists supported script files from these locations:

  • the PhonShell folder in the user's Phon application-data folder;
  • the current project's __res/PhonShell folder.

Subfolders appear as submenus. Hidden files and names beginning with ., __, or ~, or ending with ~, are omitted. Selecting a script opens a PhonShell associated with the current window and runs that script.

Use the Session Editor view

The Session Editor also provides a dockable PhonShell view. In addition to the interactive console, its toolbar can select scripts from recent files, user and project script folders, custom folders, or a file chooser. Use the play button to run the selected script; while it is executing, the same button stops it.

The view supplies editor, project, session, window, and editContextFactory context variables. Enable Send output to buffer to route script output to the entered buffer name (or phonshell when the name is blank). The tree button shows or hides current context variables, and both that visibility and the split position are saved with the editor layout.


PhonShell View