SikuliX API - headless error on macOS Big Sur (system M1)

Asked by Jeff Harmon

I am trying to use SikuliX API on MacOS Big Sur. I have created a Java program that has a main method and does a simple:

Screen screen = new Screent();

When that code executes I get an exception :

Caused by: org.sikuli.script.SikuliXception: SikuliX: Init: running in headless environment
        at org.sikuli.script.Screen.initMonitors(Screen.java:99) ~[sikulixapi-2.0.5.jar:na]
        at org.sikuli.script.Screen.initScreens(Screen.java:138) ~[sikulixapi-2.0.5.jar:na]
        at org.sikuli.script.Screen.<init>(Screen.java:198) ~[sikulixapi-2.0.5.jar:na]
        at com.phototaco.lrautomation.lrcautomate.LrcautomateApplication.ScrollLibrary(LrcautomateApplication.java:36)

I have added Terminal, Java, and VSCode (the IDE I am using) to Security & Privacy Accessibility and Screen Recording. Is there something else I am missing? This exception also happens when I run the jar file from a Terminal window

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Jeff Harmon
Solved:
Last query:
Last reply:
Revision history for this message
Jeff Harmon (phototacopodcast) said :
#1

BTW, Java 11 and SikuliX API 2.0.5

openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)

Revision history for this message
Jeff Harmon (phototacopodcast) said :
#2

I have the SilukiX IDE working just fine and can execute the script I need to work. I want to create an executable jar file that takes a couple of parameters as input that is used in the script. So if there is a better way to do that rather than writing my own Java CLI application, that would work for me as well.

Revision history for this message
Jeff Harmon (phototacopodcast) said :
#3

Seems that the issue is in GraphicsEnvironment.isHeadless() in Java AWT. This is on an M1 Mac, and it seems that evaluates to true no matter how I launched the Java application.

Tried setting DISPLAY environment variable, that didn't fix it.

Just hardcoded:

System.setProperty("java.awt.headless", "false");

and now things are working.