Using the filemaker Command by Hand

When an agent adds a field to your file through the FileMaker Agentic Development Kit (ADK), it doesn’t do anything you couldn’t do yourself. It writes a few lines of JSON and hands them to the filemaker command. In this post, we’ll set the agent aside and do that part by hand: create a table and two fields, make a mistake on purpose, and see what comes back. No AI is involved, so you can follow along in Terminal.

If you rarely open Terminal, this may look like the part of ADK you’d rather skip. Most FileMaker developers I know feel the same way. We’ve spent our careers in dialogs and the Script Workspace, not at a command prompt. But this post doesn’t ask much of you. Every command in it is shown in full, so you can copy it, paste it into Terminal, and press Return. There are only a handful of them. The only file they change is a practice file that we’ll create at the start, and the last section, which uses your own file, only reads from it.

The instructions in this post were written for a Mac. ADK runs on Windows too, and the lines of JSON that you send to the filemaker command are the same there. The Terminal commands around them are different, though, and some, like jq, don’t come with Windows, although there are probably similar ones you could find.

This is the third post in a series on ADK. What the FileMaker Agentic Development Kit is explains what the filemaker command is for, and Getting started gets it installed. Here I’ll assume you have both behind you.

Why Do This by Hand?

The filemaker command is how ADK reads and changes a file’s schema: its tables, fields, relationships, scripts, layouts and the rest. Whatever change the agent makes to your schema, it’s done using this command. When you’ve sent a few lines to it yourself, the agent’s work stops being a black box. You’ll recognize what the agent is doing when it shows you a command, and you’ll be able to read the result for yourself.

It’s also useful on its own. Some changes are quicker to type than to describe.

Two Terminal Tricks: Pipes and jq

Before we start, let’s look at two things that every command in this post uses. Once you know them, the commands are easy to read.

Open Terminal. It’s in the Utilities folder inside your Applications folder.

The first thing is the pipe, which is the | character. A pipe takes what the command on its left prints as output and hands it to the command on its right as that command’s input.

The second thing is jq, a command that comes with macOS. The filemaker command answers in JSON, one long line per answer. That’s easy for a program to read, but hard for a person. jq formats JSON so it shows one item per line, indented.

Let’s try both at once. echo is a command that prints out whatever text you give it. Here we give it a line of JSON, and the pipe hands that line to jq:

echo '{"name":"Demo","id":129}' | jq

Instead of the line coming back as you typed it, jq prints it formatted:

{
  "name": "Demo",
  "id": 129
}

That’s the pattern for the rest of the post. We’ll pipe lines into the filemaker command, and we’ll pipe what it says into jq.

There’s one more detail, and it’s the odd-looking 2>&1. A command in Terminal has two kinds of outputs: one for its results, called standard output, and one for its messages, called standard error. (Despite the name, standard error isn’t only for errors. It’s for everything that isn’t the result itself, such as warnings, progress, and summaries, so that those don’t get mixed into the results.) The filemaker command sends the results from the operations you send it as the first kind of output, and its own messages, such as the summary of each run, as the second. A pipe only redirects standard output, making that output act as input for the command to the right of the pipe. 2>&1 adds standard error to that stream, so that jq formats both.

You don’t have to remember any of this. Every command in this post that talks to a file ends the same way, with 2>&1 | jq.

post that talks to a file ends the same way, with 2>&1 | jq.

A File to Practice On

You don’t need FileMaker Pro open for this, and you don’t need a project folder. The filemaker command can create a new file for you. In Terminal, run these three commands, one at a time:

mkdir ~/filemaker-practice
cd ~/filemaker-practice
filemaker --create --file=Demo.fmp12 /dev/null 2>&1 | jq

The first two commands create a folder to work in and go into it. The third creates Demo.fmp12 in that folder. If Terminal says command not found, see the Setting Up by Hand section in the previous post, which covers getting adk and filemaker onto your PATH.

The /dev/null in the third command needs an explanation. Once the filemaker command has created the file, it keeps it open on the assumption that you’re about to send it some ops (operations) to run. After opening a session with a file, the filemaker command will continue to expect ops to run until something tells it to stop. If the ops are piped in, the end of the piped stream is the signal for it to stop. Instead of piping the ops, you can specify the name of a file that contains them at the end of the command. In that case, the end of that file is the signal to stop waiting for more ops. /dev/null is a special file that every Mac has and that is always empty. Naming it here tells the command to stop immediately after creating Demo.fmp12.

Beware: if you leave /dev/null off, the command waits for you to type the ops. Nothing seems to happen, as if it were stuck. If that happens, press Control-D to tell it that you’re done. Control-D means “end of input.” Don’t press Control-C. That would stop the command before it finished. You’d get no Demo.fmp12, just a hidden leftover file with a name like Demo.fm-cli-0q500, which you would then need to delete.

The --create option makes a new file with one table, one table occurrence and one layout, each named after the file, the way File > New does in FileMaker Pro. The file has the usual Admin [Full Access] account with no password. That’s why this command and the ones after it don’t need a username or a password. (A file that has a password needs both, which we’ll get to at the end.)

Two JSON objects are returned in the response. The first one starts with "type": "plugins", and it lists the FileMaker plug-ins that the command found on your computer. It shows up on every run, and it isn’t an error. The second is a summary of the run:

{
  "type": "summary",
  "total": 0,
  "ok": 0,
  "errors": 0,
  "dryRun": false,
  "rolledBack": false
}

We didn’t send any ops, so the summary counts zero of them.

Asking the File What It Has

Now that the file exists, let’s ask it what tables it has. This time we pipe a line in:

echo '{"op":"read:table"}' | filemaker --file=Demo.fmp12 2>&1 | jq

Here’s that command, from left to right:

  • echo prints the line that asks for the file’s tables.
  • The first pipe hands that line to the filemaker command.
  • filemaker --file=Demo.fmp12 opens a session to the Demo file and runs the line against it.
  • 2>&1 | jq formats everything that comes back.

After the plug-ins JSON object, here’s the answer to our read:table op:

{
  "op": "read:table",
  "status": "ok",
  "result": {
    "kind": "table",
    "total": 1,
    "returned": 1,
    "items": [
      {
        "name": "Demo",
        "id": 129,
        "position": 0
      }
    ]
  }
}

The file has one table, named Demo, with id 129. A summary follows, as it does on every run:

{
  "type": "summary",
  "total": 1,
  "ok": 1,
  "errors": 0,
  "dryRun": false,
  "rolledBack": false
}

One Line per Op

Every op you send is one line of JSON (called JSONL or NDJSON). Each line has an op that names a verb and a kind of object, such as create:table or read:field, followed by whatever that particular op needs. You refer to schema objects, such as tables and fields, by name. FileMaker assigns the ids and returns them in the result.

For one line, echo and a pipe are fine. For several lines, a file is easier. For example, here’s a table and two fields, with an intentional typo in the table name on the third line. In a plain text editor such as BBEdit or Visual Studio Code, make a file with these three lines, and save it as contacts.ndjson in the filemaker-practice folder:

{"op":"create:table","name":"Contacts"}
{"op":"create:field","table":"Contacts","name":"FirstName","type":"text"}
{"op":"create:field","table":"Contascts","name":"LastName","type":"text"}

Reading the Results

Here’s what came back in my run (after the plug-ins line):

{
  "op": "create:table",
  "status": "ok",
  "result": {
    "name": "Contacts",
    "id": 130,
    "position": 1,
    "occurrence": "Contacts"
  }
}
{
  "op": "create:field",
  "status": "ok",
  "result": {
    "name": "FirstName",
    "id": 1,
    "table": {
      "name": "Contacts",
      "id": 130
    },
    "position": 0
  }
}
{
  "op": "create:field",
  "status": "error",
  "error": {
    "code": "table_not_found",
    "message": "table 'Contascts' not found",
    "suggestions": [
      "Contacts"
    ],
    "line": 3
  }
}
{
  "type": "summary",
  "total": 3,
  "ok": 2,
  "errors": 1,
  "dryRun": false,
  "rolledBack": true
}

Let’s go through it:

  • Line 1 created the Contacts table, and FileMaker assigned it id 130. The result also tells us the table occurrence that was created automatically, Contacts. Just like Manage Database, the command adds an occurrence for every new table.
  • Line 2 created FirstName in Contacts, with id 1. Field ids start at 1 in every table.
  • Line 3 failed. There’s no table named Contascts. The error has an informative code (table_not_found), a human-readable explanation, a suggestion for what you might have meant (Contacts), and the line number in your ops file, so you know which op failed.
  • The summary covers the whole run. It says "rolledBack": true.

The summary is the one to read first. The three lines in your file get applied as one transaction, which means the full batch of changes will be all or nothing. Because line 3 failed, lines 1 and 2 were rolled back. The file is the same as it was before the run. You can check by listing the tables again:

echo '{"op":"read:table"}' | filemaker --file=Demo.fmp12 2>&1 | jq

The answer still lists only the Demo table.

Beware: "status": "ok" on a single line doesn’t mean that the change made it into the file. It means the line didn’t have an error. Nothing is saved until every line has been tried, and the summary is written after that. So, the summary is what tells you whether the transaction landed, not the result for each line.

The command also doesn’t stop at the first error. You can’t see that here, because the typo is on the last line. But if it had been on line 1, the command would still have tried lines 2 and 3 and answered each of them, so that you see every problem from a single run instead of one problem per run. The batch would still be rolled back at the end.

Fix It, Try It, Run It

Fix the typo in contacts.ndjson, so the third line says Contacts. Before running the batch for real, you can ask for a dry run:

filemaker --file=Demo.fmp12 --dry-run contacts.ndjson 2>&1 | jq

A dry run goes through every line exactly as a real run would and then saves nothing. In my run, all three lines came back with "status": "dry-run" instead of "ok", and the summary said "dryRun": true. (The next post will go into what a dry run does and doesn’t prove.)

Now run it for real, without --dry-run:

filemaker --file=Demo.fmp12 contacts.ndjson 2>&1 | jq

This time, all three lines came back with "status": "ok", and LastName got id 2. Here’s the summary:

{
  "type": "summary",
  "total": 3,
  "ok": 3,
  "errors": 0,
  "dryRun": false,
  "rolledBack": false
}

The summary says "rolledBack": false, so the table and both fields are in the file. If you open Demo.fmp12 in FileMaker Pro (as Admin, with no password), you’ll find them in Manage Database. Close the file again before you go on, because while FileMaker Pro has it open, the filemaker command can’t open it from its location on disk.

What happens if you run the same file a second time? Every line fails with duplicate_name, because Contacts, FirstName and LastName already exist, and the batch is rolled back. An ops file isn’t a script that you can run again to bring a file up to date. It’s a list of changes, and each change makes sense only against the file as it was when you wrote it.

Finding Your Way With filemaker help

So far, we’ve used three ops. There are many more, and thankfully you don’t need to memorize any of them. The filemaker command has its own help to guide you:

filemaker help

That lists every kind of object the command knows about, from account to variable, with one line about each. You can then ask about one of them:

filemaker help field

That gives you notes about fields, an example line, and the verbs that can be used against a field: create, read, update, delete, duplicate and search. Then you can ask about a particular verb:

filemaker help field create

That lists every key that create:field accepts, whether it’s required, and what kinds of values are valid. The answer is long, because it also covers the rules, the checks and every error the op can return. Here’s how it starts:

create:field — Creates a field in a table, with its storage, auto-enter and validation
attributes

  Keys
    table  string  required
      the table to add the field to
    name  string  required
      the field's name, unique within the table
    type  enum  required
      text | number | date | time | timestamp | container — the field's data type
    fieldType  enum  optional
      normal | calculated | summary — whether the field stores a value, computes one,
      or aggregates another field

Each answer ends by telling you what you can ask about next, so you can keep going down until you find the key you need. For example, filemaker help field create ends with:

Ask for one with `filemaker help field create <name>`. Every answer lists what you may
ask next.

Agents use the same help to learn how to run the filemaker command. When the agent needs an op it hasn’t used before, it looks it up the same way you just did.

Using It on Your Own File

Demo.fmp12 was a convenient start, because it has no password and FileMaker Pro doesn’t have it open. Your own file is different on both counts.

If FileMaker Pro has the file open, use the address that’s in your project’s adk.json instead of a path on disk. In the previous post that was fmnet://localhost/ProjectTracker. As that post explained, this only works if FileMaker Pro is sharing the file.

For the account, add --username. To use a password that you saved to the keychain during setup, add --keychain:

echo '{"op":"read:table"}' | filemaker --file=fmnet://localhost/ProjectTracker --username=admin --keychain 2>&1 | jq

In my run, that listed ProjectTracker’s two tables, Projects and Tasks.

The password came from the keychain, so the command didn’t ask for it.

There’s also --password, but beware that it makes the password visible to anyone who lists the processes running on your computer, so don’t use it. If no password is saved yet, add --prompt as well as --keychain. You’ll see a window where you can type the password, which keeps it out of the process list, and the command offers to save it to the keychain for next time.

The account you use must be [Full Access], even if all you’re doing is reading. (Post 1 explains why.)

Takeaways

The filemaker command takes one line of JSON per operation and returns a result line for each one, which jq can make readable. Read the summary first: a batch is all or nothing, and "rolledBack": true means the file wasn’t changed. A dry run tries the batch without saving it. filemaker help tells you everything else, one level at a time.

This post showed what happens when a batch fails in a single file on your own computer. The next post will look at what else protects your file while a change is made, including when the file is hosted and other people are using it, and at solutions with several files, where all or nothing applies to one file at a time.

Put ADK to Work on Your Own FileMaker Solutions

Sending a few ops by hand shows you what the agent does on your behalf. Bringing ADK into a solution your business depends on raises bigger questions, like how to test schema changes before they reach a hosted file and how your team should review what an agent proposes.

Our team can help you work through those questions for your own files and workflows. Contact us to talk about where ADK fits in your FileMaker development, and we’ll help you get started.

Leave a Comment

Your email address will not be published. Required fields are marked *

Close the CTA

GET OUR INSIGHTS DELIVERED

Scroll to Top