Calling the FoldingText Command Line interface from KeyBoard Maestro etc

Following an earlier post on Calling the FT CLI from Applescript, a quick note on tools like KeyBoard Maestro, LaunchBar, Alfred etc

These tools also run shells which differ from that of, which means that a couple of tweaks may be needed to run scripts which use the FoldingText CLI

With default settings, the command line:

echo $BASH; echo $PATH

might return something like:


But in Keyboard Maestro:


  • Explicitly export any paths your FT CLI script may need:
# A shell run by tools like KeyBoard Maestro, LaunchBar, Alfred etc may not pick up the user's bash paths
if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
	export PATH=$PATH:/usr/local/bin 
  • don’t rely on the default directory being the same as in, and

  • be aware that some familiar tools may differ slightly (in their handling of command line switches) between /bin/bash and /bin/sh

For example, instead of

wc -lm

you might have to run wc twice

wc -l
wc -m

As an example, I have updated to run with KeyBoard Maestro

and I’ve given a simple example of how you might pass command line switches to it through a Keyboard Maestro string variable.

I’ve updated the example in the repository, and the screenshot above, to reflect the discovery that the character count returned by wc -m filename can diverge significantly between and a KeyBoard Maestro Execute Shell Script action, unless we make sure that a UTF-8 setting is explicitly exported for the $LC_CTYPE locale setting.

(KM’s /bin/sh seems to default to LC_CTYPE="C" which deprives wc of the capacity to identify multi-byte characters, and makes the behaviour of wc -m simply fall back to that of the wc -c byte count.

Thus we also need something like:

# Ensure that the locale is a UTF-8 setting
if [[ "$LC_CTYPE" != *"UTF-8"* ]]; then
	export LC_CTYPE="UTF-8" 

(Doing this will enable the script to correctly keep track of the boundaries between different files in a multi file query)

Thanks for this note. That explains why Alfred workflows and LaunchBar actions get results from wc differently. Definitely keep this in my notes!!

I’m glad that seems useful. As an update - the following (slightly more fine-brushed) version should, I think, ensure that all language_region settings are preserved (and in UTF-8) in /bin/sh shells called by tools like KM:


LANGSTATE="$(defaults read -g AppleLocale).UTF-8"

if [[ "$LC_CTYPE" != *"UTF-8"* ]]; then
	export LC_ALL="$LANGSTATE" 

or in an Applescript:

do shell script "
LANGSTATE=\"$(defaults read -g AppleLocale).UTF-8\"

if [[ \"$LC_CTYPE\" != *\"UTF-8\"* ]]; then
	export LC_ALL=\"$LANGSTATE\"