简体   繁体   中英

Starting java desktop app from headless mode

I have created a java process that runs headless in the background that monitors mac machines. Part of the monitoring includes taking screenshots of the user's action and occasionally bringing up a chat window. I am under the assumption that none of these actions can be performed from headless mode, please correct me if I am wrong. Is it possible to start another process from my headless mode process that is able to open the chat window or take the screenshots? How do I start such process from the headless process? Thanks in advance.

Edit: It is running on a mac so there is definitely a monitor, a mouse, and a keyboard, and we know for a fact somebody is sitting on it and using it.

Edit: It gets started through a daemon running on the machine.

Found the following code in this link trying to run a command as the user that is signed into the machine:

loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
declare -x LoginWindowPID="$(/bin/ps -axww | /usr/bin/grep loginwindo[w] | /usr/bin/awk '/console/{print $1;exit}')"
/bin/launchctl bsexec "${LoginWindowPID:?}" /usr/bin/sudo -u "$loggedInUser" COMMAND GOES HERE

Using that we can start the java process (or any headless process) with the following command in order for it to have access to the UI:

launchctl bsexec $(/bin/ps -axww | /usr/bin/grep loginwindo[w] | /usr/bin/awk '/console/{print $1;exit}') COMMAND GOES HERE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM