Skip to content

Commit 1bb3e71

Browse files
bundoleeclaude
andcommitted
fix: pass headless JVM flags so macOS does not show Dock icon
Objective: On macOS, every CLI run pops a Java icon in the Dock and steals focus from the active window — so any batch or repeated PDF conversion turns into a flickering, focus-thrashing experience. Approach: Pass -Djava.awt.headless=true and -Dapple.awt.UIElement=true as JVM args ahead of -jar at every spawn site (Node wrapper, Python wrapper, scripts/run-cli.sh, npm export-options). The CLI never opens a UI — it only manipulates BufferedImages and renders PDFBox pages off screen — so headless is safe everywhere. apple.awt.UIElement is the macOS-specific flag the launcher reads to skip Dock registration; it is harmless on other OSes. Evidence: Ran the built jar and the Node wrapper against a sample PDF on macOS. Before: every invocation surfaced a Java Dock icon and stole focus. After (java -D... -jar): PDF processed, JSON written, no Dock icon. After (Node convert() API): variant resolved successfully, no Dock icon. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent dc73cd6 commit 1bb3e71

4 files changed

Lines changed: 26 additions & 5 deletions

File tree

node/opendataloader-pdf/src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ function executeJar(args: string[], executionOptions: JarExecutionOptions = {}):
3737
}
3838

3939
const command = 'java';
40-
const commandArgs = ['-jar', jarPath, ...args];
40+
// Force headless AWT so macOS doesn't surface a Dock icon (and steal focus)
41+
// every time the JVM touches ImageIO/PDFBox rendering. Safe on all OSes —
42+
// the CLI never opens a UI window, only manipulates BufferedImages.
43+
const commandArgs = [
44+
'-Djava.awt.headless=true',
45+
'-Dapple.awt.UIElement=true',
46+
'-jar',
47+
jarPath,
48+
...args,
49+
];
4150

4251
const javaProcess = spawn(command, commandArgs);
4352

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "OpenDataLoader PDF - Monorepo workspace",
55
"scripts": {
66
"build-java": "bash scripts/build-java.sh",
7-
"export-options": "npm run build-java && java -jar java/opendataloader-pdf-cli/target/opendataloader-pdf-cli-0.0.0.jar --export-options > options.json",
7+
"export-options": "npm run build-java && java -Djava.awt.headless=true -Dapple.awt.UIElement=true -jar java/opendataloader-pdf-cli/target/opendataloader-pdf-cli-0.0.0.jar --export-options > options.json",
88
"generate-options": "node scripts/generate-options.mjs",
99
"sync-options": "npm run export-options && npm run generate-options",
1010
"generate-schema": "node scripts/generate-schema.mjs",

python/opendataloader-pdf/src/opendataloader_pdf/runner.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@ def run_jar(args: List[str], quiet: bool = False) -> str:
1616
# Access the embedded JAR inside the package
1717
jar_ref = resources.files("opendataloader_pdf").joinpath("jar", _JAR_NAME)
1818
with resources.as_file(jar_ref) as jar_path:
19-
command = ["java", "-jar", str(jar_path), *args]
19+
# Force headless AWT so macOS doesn't surface a Dock icon (and
20+
# steal focus) every time the JVM touches ImageIO/PDFBox
21+
# rendering. Safe on all OSes — the CLI never opens a UI window,
22+
# only manipulates BufferedImages.
23+
command = [
24+
"java",
25+
"-Djava.awt.headless=true",
26+
"-Dapple.awt.UIElement=true",
27+
"-jar",
28+
str(jar_path),
29+
*args,
30+
]
2031

2132
if quiet:
2233
# Quiet mode → capture all output

scripts/run-cli.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ else
5454
ARGS=("$@")
5555
fi
5656

57-
# Run the CLI
58-
java -jar "$JAR_PATH" "${ARGS[@]}"
57+
# Run the CLI. Headless flags suppress the macOS Dock icon / focus theft when
58+
# AWT/ImageIO/PDFBox initialize. Safe on all OSes — the CLI never opens a UI.
59+
java -Djava.awt.headless=true -Dapple.awt.UIElement=true -jar "$JAR_PATH" "${ARGS[@]}"

0 commit comments

Comments
 (0)