We are pleased to release bBox version 0.96, with JSON processing via jq, Python 3 compile/run, and improvements supporting Zsh, cURL and Ruby.
bBox is a free utility plug-in to extend FileMaker solutions to easily use code libraries and macOS-based functions from Python, JavaScript, PHP, Ruby, AppleScript, C/C++, Bash/sh, XPath, and SQLite. Also included is a demo file that has over 210 examples of how you can put bBox functions to work for you.
UPDATE #1: Version 0.97 now released
Adds container reference support for Bash, cURL, Grep, Python 3, and Zsh functions and script steps. Also fixed with this update are several examples and a problem updating the displayed parameter names.
UPDATE #2: Beta Linux version
A feature incomplete version has been added for use with FileMaker Server for Linux. This version is included with the download for the macOS installer.
UPDATE #3: bBox_FileRead bug
Since version 0.96, a crash could occur when the function is given an invalid path. This is now fixed as of 10/05/2020.
System requirements for bBox v0.96 are:
- macOS 10.13 or higher*
- FileMaker 19, 18 (or 17**)
- Works with FileMaker Pro 19.1, 19, 18
- Works with FileMaker Server 18, 19
* Tested for basic compatibility with macOS 11 Big Sur Preview/beta. We will update this blog post if there are any issues with bBox 0.96 and macOS 11 Big Sur final release. ** Tested for installation compatibility with FileMaker 17, although we recommend upgrading to a newer FileMaker version (> FM 17) still supported by Claris.
New Features
bBox_JQ:
This is a new function with access to most of the features of jq, the lightweight and flexible command-line JSON processor. Although there’s some overlap with existing FileMaker JSON functions, jq can give better handling for iterating or transforming JSON data. It should give better performance than native functions when working with larger chunks of JSON.
Let’s try some simple examples. We have the the following in a variable named $json defined to contain:
[{"name":"apple","price":8}, {"name":"orange","price":10}, {"name":"peach","price":30}, {"name":"banana","price":7}]
We can easily extract every name using its iteration operator, using the -r option to give raw results:
bBox_JQ ( 0; $json; "-r"; ".[].name" )
apple orange peach banana
For a slightly more complex example, we’ll first select any records with a certain price, and then extract the names from result:
bBox_JQ ( 0; $json; "-r"; "map(select(.price > 9)) | .[].name" )
orange peach
Finally, let’s try remapping the fields:
bBox_JQ ( 0; $json; "-c"; "[.[] | {\"fruit\": .name, \"weight\": .price}]"
[{"fruit":"apple","weight":8},{"fruit":"orange","weight":10},{"fruit":"peach","weight":30},{"fruit":"banana","weight":7}]
There’s quite a bit of online content about jq, but definitely check out the jq tutorial and documentation pages.
bBox v0.96 is employing version 1.6 of jq.
bBox Python3 Run:
This is a new script step (not a function) that uses Python 3.x to compile & run the given Python script.
Unlike the Python 2.7 functions that bBox already has, the Python 3.x execution is “atomic”, since it runs in its own forked process, and allows for multiple Python instances to be running at the same time. However, once the Python script is done and the result (if any) is returned, all context & data is gone. As with several other bBox functions, you can also add the asynchronous (+4) flag to the mode parameter. This will allow FileMaker to continue running without waiting for the Python script to complete.
There is a bit of trickiness about which copy of Python 3.x is used, especially if running on macOS versions prior to Catalina. Unlike Python 2.7, Python 3.x is not installed by default. However, if you are using a Catalina or Big Sur, installation of Apple’s version of Python 3.x is usually easy — just log in to the desktop, open a Terminal window, and execute python3. A dialog will then pop up on your desktop to install Apple’s Command Line Developer Tools with a single click to start its installer. Once that’s done you’ll have a copy of Python 3.7 or later.
If this was a system where macOS was upgraded at some point, it may sometimes take some extra fiddling to get the command line tools installed. Often running this command will resolve the installer issue:
xcode-select --install
With that hopefully done, the python3 command will be installed at:
/usr/bin/python3
This is also the default path used by the bBox Python3 Run script step.
But what if you are using a macOS version prior to Catalina? Or, you want bBox’s script step to use a different version of Python than what Apple installs? For these scenarios, add the “Use Alternate” (+16) option to the mode parameter, and bBox will attempt to use the Python version at this path instead:
/usr/local/bin/python3
The above location is also the path that the Python Software Foundation’s official Python 3 installer will use. You can get the macOS installers for Python here: https://www.python.org/downloads/mac-osx/
Bash/Shell/Zsh Error Messages:
Previously, if your script generated a shell error, the bBox_LastError function would give you a generic version with the POSIX error code number, and it was up to you to determine the meaning of the codes. Now, bBox v0.96 will give an explanatory message for most errors. Unfortunately, this will not cover any error codes returned by commands your shell scripts run — you’ll have to refer to to documentation or source code of the command to determine the meaning of its result codes.
bBox_Ruby:
Similar to the new python3 script step, the bBox_Ruby function now supports the “Use Alternate” (+16) mode flag. If set, it will attempt to use the Ruby interpreter installed here:
/usr/local/bin/ruby
Bug Fixes
bBox_Curl: bBox_LastError will now only return the error result for the last call to the function, instead of the last non-zero result.
Resources
Download bBox plugin
bBox product page
Apple XCode Downloads and Resources
– Simon