skills

4D Method Runner

Run a 4D project method with the right runtime.

Choose the Runtime First

Prefer this fallback strategy because it is usually faster than deciding up front from incomplete context.

Finding tool4d

tool4d can be located in two ways:

1. Environment Variable

Set TOOL4D to the tool4d executable:

export TOOL4D="/path/to/tool4d.app/Contents/MacOS/tool4d"

2. Auto-discovery from Extension

tool4d is typically installed by the 4D-Analyzer extension in one of these locations:

Use scripts/find_tool4d.py to return the newest installed executable.

python3 <skill-dir>/scripts/find_tool4d.py

The script checks:

Running with tool4d

"<tool4d_path>" --project="<project_path>" --startup-method="<method_name>" --skip-onstartup --dataless

Parameters:

Example:

SKILL_DIR="/path/to/4d-run"
TOOL4D="$(python3 "$SKILL_DIR/scripts/find_tool4d.py")"
"$TOOL4D" --project="/path/to/MyProject/MyProject.4DProject" --startup-method="test_MyFeature" --skip-onstartup --dataless

Running with the Full 4D Runtime

Ask the user for the 4D executable path first:

Then run the helper:

SKILL_DIR="/path/to/4d-run"
python3 "$SKILL_DIR/scripts/run_with_4d.py" \
    "/Applications/4D.app" \
    "/path/to/MyProject/MyProject.4DProject" \
    "test_UsesDatabase"

run_with_4d.py launches the runtime, waits for it to exit, and kills it after 30 seconds by default if it is still running.

Important:

Equivalent direct command if you already know the binary path:

"C:\Program Files\4D\4D.exe" \
    --project="/path/to/MyProject/MyProject.4DProject" \
    --startup-method="test_UsesDatabase" \
    --skip-onstartup

Output Handling

When deciding whether to fall back from tool4d to full 4D, treat these as fallback signals:

Do not fall back automatically for ordinary method bugs. If the method itself is wrong, report the failure instead of switching runtimes.

Logging from 4D Code

Use LOG EVENT to output messages:

LOG EVENT(Into system standard outputs; "message"; Information message)

Or write to a file:

File("/path/to/debug.txt").setText($debugText)

Workflow

  1. Locate the .4DProject file.
  2. Decide whether tool4d is clearly sufficient, clearly insufficient, or unclear.
  3. If it is unclear, try tool4d first because that is usually the fastest path.
  4. If tool4d succeeds, keep using it.
  5. If tool4d fails for a likely runtime/database limitation, ask the user for the 4D executable path and retry with full 4D.
  6. When using the full runtime, ensure the method calls QUIT 4D or use scripts/run_with_4d.py so the process gets cleaned up.