1

I've been trying to get this to work but haven't had any success.

I have this jar file: /Users/ivanmorelos/Documents/guiprueba.jar

I also made this sh file:

#!/bin/bash
java -jar guiprueba.jar

the path to this sh is: /Users/ivanmorelos/Documents/guiprueba.sh

If I run this script from the terminal like

bash /Users/ivanmorelos/Documents/guiprueba.sh

then the jar executes perfectly.

Now I went to /Library/LaunchDaemons/ and made the following com.ivan.gui.plist:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple$
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.ivan.gui</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/ivanmorelos/Documents/guiprueba.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>UserName</key>
    <string>root</string>
</dict>
</plist>

*I made the sh executable and it belongs to ivanmorelos, so does the jar file.

*The plist belongs to root.

As I understand this should make my jar execute at boot time and therefor, before the login screen comes up. Am I correct? But any way nothing happens and I don't know where the error is. Could you please help me? I would really appreciate it.

EDIT

I made the following change in the script:

java -jar guiprueba.jar

for

touch texto.txt

to create a simple file but it still doesn't do it.

8
  • Have both files (the daemon and the script) access privileges root:wheel 644 ? They have to. And the script is supposed to be located also in the main library. The keepAlive key is actually not needed unless the script uses a run loop. Commented Jul 28, 2016 at 16:59
  • Hi @vadian, both files have 644 privileges. What do you mean by main library? Should I move the script to /Library/? Commented Jul 28, 2016 at 18:25
  • It's more important that the owner is root and the group is wheel. And yes, move the script to /Library maybe in a subfolder of Application Support since the daemon runs in the local domain. Commented Jul 28, 2016 at 18:30
  • @vadian yes the owner is root and group is wheel. I moved the script to /Library but still doesnt work Commented Jul 28, 2016 at 19:09
  • I assume you have adjusted the path to the scripting the plist file. And did you load the daemon once with launchctl and sudo? Commented Jul 28, 2016 at 19:18

1 Answer 1

2

So I finally found the solution to this problem.

I left my jar at /Users/ivanmorelos/Documents/ owned by root:wheel. A ls -l shows this:

-rw-r--r--  1 root  wheel  2365 Jul 29 11:27 guiprueba.jar

Then moved my plist to /System/Library/LaunchDaemons/ with the following permissions:

-rw-r--r--  1 root  wheel  372 Jul 29 12:49 com.ivan.plist

Also moved my script to /usr/sbin/ with the following permissions:

-rwxr-xr-x  1 root  wheel  129 Jul 29 13:07 /usr/sbin/guiprueba

and as the ls -l shows I removed the .sh

And that's it. Now my script and jar execute at boot time.

This is the final plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs$
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.ivan</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/sbin/guiprueba</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>
Sign up to request clarification or add additional context in comments.

2 Comments

This solution apparently does not work in macOS Catalina because of the new security restrictions (read-only volume). How did you manage that?
It's better to place your custom script in /usr/local/bin -- that's where 3rd party scripts and unix apps normally go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.