← back to Dw Photo Capture

FILEMAKER-STICKER-SETUP.md

108 lines

# FileMaker Sticker — setup

The scanner side is LIVE and already stamps `Date WP Sample Sent` = today when you press Print.
These steps add the **physical Zebra print**. They must be done in FileMaker Pro (the Data API
can't create fields or scripts).

> **STATUS 2026-07-06:** ✅ **STEP 1 DONE.** `web_print_request` (Text) is created on the Sample
> Requests base table and placed on the `Sample Requests via email` layout (verified unprefixed via
> the Data API). Server config `FM_PRINT_FLAG_FIELD=web_print_request` is set on Kamatera, live
> (`FM_WRITE=1`). dryRun-verified: pressing Print writes `Date WP Sample Sent`=today **and**
> `web_print_request`=`sku`/`address` to the scanned record. **Only STEP 2 (the poller) remains** —
> point its two `Perform Script` lines at your existing Zebra print scripts and arm it.

--------------------------------------------------------------------------------
## STEP 1 — add the flag field  (~45 sec)  — TWO parts, both required

**1a. Create the field.** FileMaker Pro → **File ▸ Manage ▸ Database… ▸ Fields tab** → select the
table behind `Sample Requests via email` (the `WALLPAPER` table) →
- **Field Name:** `web_print_request`
- **Type:** Text
- click **Create**, then **OK**.

**1b. Place it on the layout** (the Data API can ONLY read/write fields that exist on the layout it
targets — skip this and the write fails "field not found"). Go to the **`Sample Requests via email`**
layout → **Layout mode** (⌘L) → drag the new `web_print_request` field anywhere onto the layout (a
corner is fine; it can be tiny) → **Exit Layout** → **Save**.

Then tell me "field created" and I set `FM_PRINT_FLAG_FIELD=web_print_request` on the server
(1 command). I verify it's live by reading the layout's field list back over the API — the instant
`web_print_request` shows up there, the Print button writes `sku`/`address` into it for the scanned
record.

--------------------------------------------------------------------------------
## STEP 2 — add the poller script  (~90 sec)
FileMaker Pro → **Scripts ▸ Script Workspace ▸ New Script**, name it `Web Sticker Poller`,
paste these steps (adjust the two `Perform Script` names to YOUR existing print/stamp scripts):

```
# Web Sticker Poller  — run via Install OnTimer on an open "Sticker Station" window
Enter Find Mode [ Pause: Off ]
  Set Field [ WALLPAPER::web_print_request ; "*" ]     # any non-empty flag
Perform Find [ ]
If [ Get(FoundCount) > 0 ]
  Go to Record/Request/Page [ First ]
  Loop
    # branch on the flag value to pick the sticker size:
    If [ WALLPAPER::web_print_request = "address" ]
      Perform Script [ "PRINT ADDRESS STICKER" ]       # <-- your existing address-label script
    Else
      Perform Script [ "PRINT SKU STICKER" ]           # <-- your existing SKU/Zebra label script
    End If
    # your print script already stamps Date WP Sample Sent = today; if not, uncomment:
    # Set Field [ WALLPAPER::Date WP Sample Sent ; Get(CurrentDate) ]
    Set Field [ WALLPAPER::web_print_request ; "" ]    # clear so it doesn't reprint
    Commit Records/Requests [ No dialog ]
    Go to Record/Request/Page [ Next ; Exit after last ]
  End Loop
End If
```

Then a tiny **`Start Sticker Station`** script that arms it (run once when you sit down to send samples):
```
Install OnTimer Script [ "Web Sticker Poller" ; Interval: 4 ]
```
Open a window on any layout of the WALLPAPER table, run `Start Sticker Station`, and leave it open
on the Mac attached to the Zebra. It'll print + clear each flagged record every 4s.

--------------------------------------------------------------------------------
## What I do (once STEP 1 is done)
- Set `FM_PRINT_FLAG_FIELD=web_print_request` on Kamatera + restart (1 command).
- Verify end-to-end: scan → popup → Print → confirm the flag lands on the record (I can read it back)
  and `Date WP Sample Sent` stamps today.

--------------------------------------------------------------------------------
## "USE BOTH" — both print mechanisms are built. ARM ONLY ONE AT A TIME.
Both A (FileMaker OnTimer poller) and B (Mac watcher) watch the same `web_print_request` flag and
clear it after printing. **Running both simultaneously double-prints** (race on the flag) — so keep
one ARMED (auto-printing) and the other as a manual/standby fallback. DTD verdict favored A for
reliability; B is built for when you'd rather not keep a FileMaker window armed.

### Option B — Mac-side watcher (built, staged, NOT yet started)
Files: `sticker-watcher.js` + `launchd/com.steve.dwphoto-sticker-watcher.plist`. It runs on the Mac
by the Zebra, polls FileMaker for flagged records, fires your print script via AppleScript, clears
the flag. To ACTIVATE (after STEP 1 field exists):
1. Edit the plist's `FM_PRINT_SCRIPT_SKU` / `FM_PRINT_SCRIPT_ADDR` to your real script names.
2. Your print script must accept the passed **combo sku** as its parameter and go to that record.
   If it just prints the current record, add this tiny wrapper script and point the plist at it:
   ```
   # Print Flagged Record (param = combo sku)
   Enter Find Mode [] · Set Field [ WALLPAPER::combo sku ; Get(ScriptParameter) ] · Perform Find []
   If [ Get(FoundCount) = 1 ] · Perform Script [ "YOUR EXISTING PRINT SCRIPT" ] · End If
   ```
3. Grant Automation permission (macOS will prompt: Terminal/node → control "FileMaker Pro").
4. `cp launchd/com.steve.dwphoto-sticker-watcher.plist ~/Library/LaunchAgents/ &&`
   `launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.steve.dwphoto-sticker-watcher.plist`
   (remove: `launchctl bootout gui/$(id -u)/com.steve.dwphoto-sticker-watcher`).
   Keep FileMaker Pro open on that Mac. Logs: `sticker-watcher.log`.

### To use A instead: don't start the watcher; paste the FileMaker poller (STEP 2 above). Use one.

--------------------------------------------------------------------------------
## (legacy) zero-scripting alternative
If your Zebra Mac stays open, I can instead build a tiny Mac-side watcher (launchd + AppleScript
`tell application "FileMaker Pro" to do script "<your print script>"`) that polls the flag and fires
your existing print script — no new FileMaker script needed. Tell me your print script's exact name
and which Mac has the Zebra, and I'll build that instead.
```