The CLI for FoldingText TaskPaper and MD enables us to filter and query across several different text files (temporarily concatenated with suitable delimiters) producing reports and perspectives which give a useful overview.
It works very well from the Terminal.app command line, and from shell scripts. Here are a couple of basic notes in case anyone else also wants to call it from Applescript, perhaps to make use of Applescript’s
choose from list menus.
- The shell used by
do shell scriptis not your default Terminal.app shell
- Your Terminal.app search paths, working directory, and other settings are not exported to it.
- Search paths and other such settings don’t persist between successive calls to
do shell script– you need to set things up each time you use it.
Point 1 means that you may occasionally need to watch out for slightly different responses to command line switches.
For example, both Terminal.app and Applescript’s
do shell script respond to:
with something like
49 280 1828 notes-2014-07-11.txt
wc -lm notes-2014-07-11.txt in Terminal.app (standard Bash) yields:
49 1828 notes-2014-07-11.txt
do shell script "wc -lm notes-2014-07-11.txt"
we just get:
So if you notice any slight departures from what is happening in Terminal.app, just experiment and test.
Point 2 means that you need to tell the Applescript about any search paths & working directories and perhaps full paths to any executables that you need. In particular:
- the NPM files needed by the FT CLI are usually installed to
- and you will need to specify exactly where the
ftCLI binary is installed on your system.
For example, to run the simple command line test:
$ ft get "//not @done" myfile.ft
from Applescript, you could assemble and pass to
do shell script a string like:
export PATH=$PATH:/usr/local/bin cd "$(dirname '/Users/houthakker/Desktop/test.scpt')" '/usr/local/lib/node_modules/foldingtext/bin/ft' get '//not @done' myfile.ft
which you could do with Applescript along the lines of:
property pstrPathtoFTCLI : "/usr/local/lib/node_modules/foldingtext/bin/ft" on run callFT("get '//not @done' myfile.ft") end run on callFT(strArgs) set strScriptPath to POSIX path of (path to me) -- path to this script set strCMD to "export PATH=$PATH:/usr/local/bin cd \"$(dirname " & quoted form of strScriptPath & ")\" " & quoted form of pstrPathtoFTCLI & space & strArgs return (do shell script strCMD) end callFT
Point 3 means that if you follow this up with another
do shell script in the following line, your paths and working directories will not have been remembered - you need a little setup header for every call.