Scripting Language Configuration

Panorama allows you to embed code written in Perl, PHP, Python and Ruby into Panorama code. However, in recent versions of macOS these languages are no longer included as part of macOS. In that case, you’ll need to install the language you want to use yourself. Or even if the language you want to use is already installed, you may want to install a newer version (Apple tends to include older, somewhat obsolete versions). Once you’ve installed the version you want, you can configure Panorama to use that version.

### Installing Scripting Languages

It’s possible to install scripting languages manually, but an easier method is to use a package manager. The most popular package managers available on macOS are Homebrew and MacPorts.

- Homebrew – https://brew.sh
- MacPorts – https://www.macports.org

Both of these package managers have installation packages for all four of the scripting languages that Panorama supports. Pick the package manager that you want to use, then follow the package manager instructions to install the language(s) you want to use.

Note: In the case of Python, you can also easily download and install it directly from the Python web site at `https://www.python.org/downloads/`.

### Default Configuration

By default, Panorama will use the scripting language built in to macOS, if any. So if you’re using a version of macOS that includes the language you want to use, no configuration is necessary.

If macOS doesn’t include a particular scripting language, Panorama will look for that language in the default installation location used by Homebrew:

    /opt/homebrew/bin/

If the language isn’t found there, Panorama will look in the default installation location used by MacPorts:

    /opt/local/bin

So in most cases no configuration is needed at all – Panorama will automatically find the language for you.

### Custom Configuration

If you’ve installed a scripting language in a non-default location, or if you have multiple copies of a scripting language installed and you want to specify which one to use, you’ll need to set up a custom configuration. This is done by opening the Preferences window and then switching to the Advanced tab.

The Scripting Languages panel contains two sections. The top section displays a table showing the status of the languages that Panorama is currently configured to use.

The first column of this table lists the four languages in alphabetical order.

The second column of the table lists the version number of this language. If the version number is empty, the language isn’t installed.

The third column of the table shows the location of the configured language.

#### Custom Paths for Scripting Languages

If you want to use a scripting language in a non-default location, you’ll need to type the location into the Custom paths box. If you have custom paths for more than one language, it doesn’t matter what order you type them in. (However, if you type in two or more different paths for a single language, only the first path will be used.)

In this example, both Python and PHP are using custom configurations. Python has been customized to use Python 3 instead of the default Python 2, and PHP has been configured to use a copy of PHP installed via Homebrew. This copy of PHP is quite a bit newer than the default copy that came with this macOS 11 (Big Sur) system.

When you edit the custom paths, the status display will update as soon as you press the Enter key, so you’ll immediately be able to see if you typed in the correct path.

Customizing Paths in Code

If you want to access the custom paths directly in code, use the Panorama preference `PXScriptBinPaths`. For example, suppose you had some code you wanted to run using Python3, even if Python 2 is the current configuration. You can force the use of Python 3 with code like this:

    let wasCustomPaths = catcherror("",getpreferencevalue("PXScriptBinPaths"))
    setpreferencevalues "PXScriptBinPaths","/usr/bin/python3"
    let result = python("some...python...3...code...here")
    setpreferencevalues "PXScriptBinPaths",wasCustomPaths

Of course this assumes that Python3 is in fact installed on this computer. Remember, this is no longer guaranteed on all versions of macOS.

See Also

- applescript -- executes an AppleScript.
- applescript( -- executes AppleScript source code and returns the result.
- blindposixscript( -- executes a POSIX shell script using NSTask and returns the process id.
- executeapplescript -- compiles and runs an AppleScript.
- executeperlscript -- executes Perl code.
- executesudounix -- executes a UNIX shell command using *sudo* (root) privileges.
- executeunix -- executes a UNIX shell command.
- info("posixtasks") -- list of POSIX shell tasks running in the background.
- perl -- executes a Perl script (program).
- perl( -- executes a perl program and returns the result (stdout).
- php -- executes a PHP script (program).
- php( -- executes a PHP program and returns the result.
- posixscript( -- executes a POSIX shell script using NSTask and returns the result.
- posixtask -- executes a POSIX shell script in the background using NSTask.
- posixtask( -- executes a POSIX shell script in the background using NSTask.
- python -- executes a Python script (program).
- python( -- executes a python program and returns the result (stdout).
- ruby -- executes a Ruby script (program).
- ruby( -- executes a ruby program and returns the result (stdout).
- scriptbglog -- specifies a path/file for output from STDOUT from embedded programs run in the background (Perl, Ruby, Python, PHP).
- scripttimeout -- sets the maximum runtime allowed for an embedded program (AppleScript, ShellScript, Perl, Ruby or Python).
- shellscript -- executes a UNIX shell script.
- shellscript( -- executes a UNIX shell script and returns the result.
- stopposixtask -- stops a POSIX shell script that is running in the background.
- usebashprofile -- grabs the search path from the `.Bash_profile` file in the user's home folder, so that these paths will be used by scripting languages (*Ruby, Python*, etc.).
- xcallbackurl -- performs an action in another application using the x-callback-url mechanism.

History

Version | Status | Notes
10.2 | New | New in this version.