If I open a terminal and run the below script, it works fine. The values from the gdbus call get written to the lockScreenTest.txt file. The values are true when the screen is locked and the values are false when the screen is unlocked.
#!/bin/bash
while true; do
echo "$(gdbus call -e -d com.canonical.Unity -o /com/canonical/Unity/Session -m com.canonical.Unity.Session.IsLocked)" >> lockScreenTest.txt
sleep 2
echo "called" >> lockScreenTest.txt
done
But if I add this line ./lockScreenCheck.sh& to ~/.profile and restart the computer, the output of gdbus doesn't get written to lockScreenTest.txt. Instead, only the following output is written:
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
called
Why isn't the output of gdbus available when the script is run from ~/.profile?
I'm investigating this because I wrote a Java program which needs to check if the screen is locked, and I'm doing it with roughly the following commands:
String command = "gdbus call -e -d com.canonical.Unity -o /com/canonical/Unity/Session -m com.canonical.Unity.Session.IsLocked";
p = Runtime.getRuntime().exec(command);
p.waitFor();
Like the bash script, the Java program also works fine if I run it from a terminal with java -jar program.jar, but if I invoke it from ~/.profile, the Java program runs, but the output from the gdbus command is elusive.