Posted on 04-28-2015 09:12 AM
I have a dockutil script that works great, but when I try to add a line for a parameter it gets kind of funky.
Currently the script is written as:
ConUser=`/bin/ls -l /dev/console | awk '//{print $3 }'`
#Remove All Dock Items
sudo -u $ConUser dockutil --remove all --no-restart
#Add Dock Items
sudo -u $ConUser dockutil --add /Applications/Safari.app
sudo -u $ConUser dockutil --add /Applications/Google Chrome.app
sudo -u $ConUser dockutil --add /Applications/iPhoto.app
sudo -u $ConUser dockutil --add /Applications/Microsoft Office 2011/Microsoft Word.app
sudo -u $ConUser dockutil --add /Applications/Microsoft Office 2011/Microsoft Excel.app
sudo -u $ConUser dockutil --add /Applications/Microsoft Office 2011/Microsoft PowerPoint.app
sudo -u $ConUser dockutil --add /Applications/Dictionary.app
sudo -u $ConUser dockutil --add /Applications/Calculator.app
sudo -u $ConUser dockutil --add $4
In the dock policy I have added a parameter ($4) in this case that is:
/Applications/Google Earth.app
I have escaped the space as well as tried using quotes, but the script still ends up failing. I tried removing the space from the application on the client and then also removing the space from the parameter and the icon is then added.
So my question is why the space is being ignored? What the script is only seeing when the space is there is "Earth.app" and tries to look for it as a home directory or plist.
The error I get from the log:
Script exit code: 1 Script result: Earth.app' does not seem to be a home directory or a dock plist
My end goal here is to allow our field techs to have a predefined dock and they can add additional dock items specific to their schools via the parameter option.
Posted on 04-28-2015 09:43 AM
I had to start using single quotes (I think when Yosemite came out?), this is with Dockutil 2.0.2 which was also updated for Yosemite.
#!/bin/bash
DOCKUTIL=/usr/local/bin/dockutil
$DOCKUTIL --remove all
$DOCKUTIL --add '/Applications/Launchpad.app' --no-restart
$DOCKUTIL --add '/Applications/Google Chrome.app' --no-restart
$DOCKUTIL --add 'System Preferences' --no-restart
$DOCKUTIL --add '~/Downloads'
exit 0
Posted on 04-28-2015 10:13 AM
We are on Casper 9.62 and there were some issues with spaces prior to 9.72 so I'm going to upgrade our JSS and see what the results are.
Posted on 04-28-2015 10:17 AM
That bug is unrelated. That had to do with package file names.
To test, I would change the last line to
echo sudo -u $ConUser dockutil --add $4
so you can see what it thinks $4 is.
Posted on 04-28-2015 10:27 AM
@peterj04 listed below is what I use along with a launch agent
#!/bin/bash
# Running checkSetupDone function to determine if the rest of this script needs to run.
# Yes, if $HOME/Library/Preferences/com.viasat.docksetup.plist file does not exist.
# Otherwise, assume this setup script has already run for this user and does not
# need to run again.
checkSetupDone() {
if [ -f $HOME/Library/Preferences/com.company.docksetup.plist ] ; then
exit 0
fi
}
configureDefaultDock() {
DOCKUTIL=/usr/local/bin/dockutil
$DOCKUTIL --remove all --no-restart
$DOCKUTIL --add '/Applications/Launchpad.app' --no-restart
$DOCKUTIL --add '/Applications/Safari.app' --no-restart
$DOCKUTIL --add '/Applications/Self Service.app' --no-restart
$DOCKUTIL --add '/Applications/Mission Control.app' --no-restart
$DOCKUTIL --add '/Applications/Microsoft Office 2011/Microsoft Word.app' --no-restart
$DOCKUTIL --add '/Applications/Microsoft Office 2011/Microsoft Outlook.app' --no-restart
$DOCKUTIL --add '/Applications/Microsoft Office 2011/Microsoft PowerPoint.app' --no-restart
$DOCKUTIL --add '/Applications/Microsoft Office 2011/Microsoft Excel.app' --no-restart
$DOCKUTIL --add '/Applications/Microsoft Lync.app' --no-restart
$DOCKUTIL --add '/Applications/Cisco/Cisco AnyConnect Secure Mobility Client.app' --no-restart
$DOCKUTIL --add '/Applications' --no-restart
$DOCKUTIL --add '~/Downloads'
touch $HOME/Library/Preferences/com.viasat.docksetup.plist
}
checkSetupDone
configureDefaultDock
exit 0
Posted on 04-28-2015 11:26 AM
Oddly enough when I add the echo command it appears that it's doing exactly what it should be doing, but the icon still doesn't show up.
Executing Policy barton-Student Dock with Custom TEST... Running script Dock Default - Student Custom... Script exit code: 0 Script result: sudo -u barton-stutest dockutil --add /Applications/Google Earth.app
As you can see, it is adding in the proper backslash automatically, however the dock item still isn't being added to the dock for some reason. If I remove the echo command it reverts back to incorrect syntax being passed which states that "Earth.app" is not a home directory or plist.
I don't know much about scripting so I apologize so I'm quite lost now. I will have to do some further testing tomorrow.
Posted on 04-28-2015 11:53 AM
@peterj04 I just tested using a variable for the application name with my method of deploying, and it appears to work fine. You might try it this way:
#!/bin/sh
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
myUser="/Users/${loggedInUser}"
# set the path to dockutil
du='/private/var/inte/bin/dockutil'
$du --add "$4" $myUser
Posted on 04-28-2015 12:03 PM
I see you used double quotes around the $4 parameter. I added single quotes at one point and still experienced the same results, but I have not tried double quotes if that makes a difference.
I will have to test further with the above examples and see what I find out. Thank you all for the replies!
Posted on 04-28-2015 06:10 PM
as everyone else has already said single quotes if you list the path
ie
/usr/local/bin/dockutil --add '/Applications/Microsoft Office 2011/Microsoft Word.app'
Double quotes if the app is in a variable
/usr/local/bin/dockutil --add "$my_app"
Posted on 04-29-2015 06:38 AM
Well ultimately the problem appears to be that...
#!/bin/sh
...was missing, once I added that to the top of the script, things seemed to have started working now. Since I don't write scripts and was using a script that someone else originally created, I didn't know any better.
Thanks for everyones help!