kcrawford / dockutil

command line tool for managing dock items
http://patternbuffer.wordpress.com
Apache License 2.0
1.38k stars 131 forks source link

Running Dockutil at login through LaunchAgent doesn't work? #50

Closed hidesminimally closed 8 years ago

hidesminimally commented 9 years ago

My problem is very straight forward: I'm trying to run commands for every user that logs in through using a LaunchAgent that runs a bash script:

#!/bin/bash
#/usr/bin/testing.sh

mkdir -p /Users/myname/Created

/usr/local/bin/dockutil --add "/Users/myname/Networks"
sudo dockutil --add "/usr/bin"
sudo dockutil --add "/usr/"
sudo dockutil --list > /Users/myname/Desktop/test.txt

In /Library/LaunchAgents/com.myname.test.plist :

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.sait.test.app</string>
        <key>ProgramArguments</key>
        <array>
                <string>/bin/sh</string>
                <string>/usr/bin/testing.sh</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StandardOutPath</key>
        <string>/var/log/myjob.log</string>
        <key>Debug</key>
        <true/>

    </dict>
    </plist>

The folder is created on login. But, none of the DockUtil commands are executed. That is, my dock isn't changed and the test.txt doesn't contain any text. When I run these manually in the terminal, they work fine.

Why is this? Is there something that is wrong with how dock-util is loaded, or how it executes that I'm not aware of?

erikng commented 9 years ago

I use outset to trigger dockutil

https://github.com/chilcote/outset

Sent from my iPhone

On Nov 3, 2015, at 12:58 PM, Daniel Li notifications@github.com wrote:

My problem is very straight forward: I'm trying to run commands for every user that logs in through using a LaunchAgent that runs a bash script:

!/bin/bash

/usr/bin/testing.sh

mkdir -p /Users/myname/Created

/usr/local/bin/dockutil --add "/Users/myname/Networks" sudo dockutil --add "/usr/bin" sudo dockutil --add "/usr/" sudo dockutil --list > /Users/myname/Desktop/test.txt In /Library/LaunchAgents/com.myname.test.plist :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.sait.test.app</string>
    <key>ProgramArguments</key>
    <array>
            <string>/bin/sh</string>
            <string>/usr/bin/testing.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/var/log/myjob.log</string>
    <key>Debug</key>
    <true/>

</dict>
</plist>

The folder is created on login. But, none of the DockUtil commands are executed. That is, my dock isn't changed and the test.txt doesn't contain any text. When I run these manually in the terminal, they work fine.

Why is this? Is there something that is wrong with how dock-util is loaded, or how it executes that I'm not aware of?

— Reply to this email directly or view it on GitHub.

mvught commented 9 years ago

@lilshim, did you change the plist with chown in the terminal? Root / wheel

hidesminimally commented 9 years ago

@mvught This means running sudo chown root /Library/LaunchAgents/com.myname.test.plist right?

mvught commented 9 years ago

Sudo chown root:wheel com.myname.test.plist

hidesminimally commented 9 years ago

@mvught yeah.. tried that... no difference.

kcrawford commented 9 years ago

You should not attempt to run as root within a Launch Agent in Aqua context. (Remove sudo)

In general it is best to not run dockutil as root. When run as the user it is more likely that cfprefs works properly.

Kyle

Sent from Mobile

On Nov 3, 2015, at 1:58 PM, Daniel Li notifications@github.com wrote:

My problem is very straight forward: I'm trying to run commands for every user that logs in through using a LaunchAgent that runs a bash script:

!/bin/bash

/usr/bin/testing.sh

mkdir -p /Users/myname/Created

/usr/local/bin/dockutil --add "/Users/myname/Networks" sudo dockutil --add "/usr/bin" sudo dockutil --add "/usr/" sudo dockutil --list > /Users/myname/Desktop/test.txt In /Library/LaunchAgents/com.myname.test.plist :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN  "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.sait.test.app</string>
    <key>ProgramArguments</key>
    <array>
            <string>/bin/sh</string>
            <string>/usr/bin/testing.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/var/log/myjob.log</string>
    <key>Debug</key>
    <true/>

</dict>
</plist>

The folder is created on login. But, none of the DockUtil commands are executed. That is, my dock isn't changed and the test.txt doesn't contain any text. When I run these manually in the terminal, they work fine.

Why is this? Is there something that is wrong with how dock-util is loaded, or how it executes that I'm not aware of?

— Reply to this email directly or view it on GitHub.

mvught commented 8 years ago

Hello lilshim, did you have any progress with your test?

mvught commented 8 years ago

lilshim,

Can you try this below:


!/bin/bash

/usr/bin/testing.sh

dockutil="/usr/local/bin/dockutil" mkdir -p /Users/myname/Created

$dockutil --add "/Users/myname/Networks" /bin/sleep 10 $dockutil --add "/usr/bin" /bin/sleep 10 $dockutil --add "/usr/" /bin/sleep 10 $dockutil --list > /Users/myname/Desktop/test.txt

kcrawford commented 8 years ago

Please test with latest version (2.0.3) or newer.

kcrawford commented 8 years ago

I'm going to close this. Please test with latest version.