kcrawford / dockutil

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

I am getting several errors when running the following #151

Closed Hollywoodcole7 closed 8 months ago

Hollywoodcole7 commented 1 year ago

!/bin/bash

check if dockutil is installed, install if it's not.

dockutil="/usr/local/bin/dockutil" if [[ -x $dockutil ]]; then echo "dockutil found, no need to install" else echo "dockutil could not be found, installing..." curl -L --silent --output /tmp/dockutil.pkg "https://github.com/kcrawford/dockutil/releases/download/3.0.2/dockutil-3.0.2.pkg" >/dev/null

install dockutil

installer -pkg "/tmp/dockutil.pkg" -target /

fi

vars to use script and set current logged in user dock

killall="/usr/bin/killall" loggedInUser=$( ls -l /dev/console | awk '{print $3}' ) LoggedInUserHome="/Users/$loggedInUser" UserPlist=$LoggedInUserHome/Library/Preferences/com.apple.dock.plist ################################################################################

Use Dockutil to Modify Logged-In User's Dock

################################################################################ echo "------------------------------------------------------------------------" echo "Current logged-in user: $loggedInUser" echo "------------------------------------------------------------------------" echo "Removing all Items from the Logged-In User's Dock..." sudo -u $loggedInUser $dockutil --remove all --no-restart $UserPlist echo "Creating New Dock..." sudo -u $loggedInUser $dockutil --add "/Applications/Google Chrome.app" --no-restart $UserPlist sudo -u $loggedInUser $dockutil --add "/Applications/Adobe Photoshop 2023/Adobe Photoshop 2023.app --no-restart $UserPlist sudo -u $loggedInUser $dockutil --add "/Applications/Adobe Illustrator 2023/ Adobe Illustrator 2023.app" --no-restart $UserPlist sudo -u $loggedInUser $dockutil --add "/Applications/Adobe InDesign 2023/ Adobe InDesign.app" --no-restart $UserPlist sudo -u $loggedInUser $dockutil --add "/Applications/zoom.us.app" --no-restart $UserPlist sudo -u $loggedInUser $dockutil --add "/Applications/Spotify.app" --no-restart $UserPlist sudo -u $loggedInUser $dockutil --add "System/Applications/System Preferences.app" --no-restart $UserPlist sudo -u $loggedInUser $dockutil --add "~/Downloads" --section others --view auto --display folder --no-restart $UserPlist echo "Restarting Dock..." sudo -u $loggedInUser $killall Dock

exit 0

It appears that the dockutil pull request and install works great. However, when the current user request happens along with the rest of the code I get errors The Errors look like this:

Current logged-in user: admin

Removing all Items from the Logged-In User's Dock... usage: sudo -h | -K | -k | -V usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user] usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command] usage: sudo [-AbEHknPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s] [] usage: sudo -e [-AknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ... Creating New Dock... sudo: unrecognized option --add' usage: sudo -h | -K | -k | -V usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user] usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command] usage: sudo [-AbEHknPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s] [<command>] usage: sudo -e [-AknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ... /bin/bash: line 23: unexpected EOF while looking for matching"' /bin/bash: line 27: syntax error: unexpected end of file

Sorry, I am very new to this, and I really would like this to work so I can send this via Unix command over Apple remote desktop. Thus far I have been just trying to work within terminal on a single machine, without ARD, but ARD is the ultimate goal. Any insight as to what I may be doing wrong?

kcrawford commented 8 months ago

It looks like sudo is not getting the $loggedInUser for the -u option so it is using $dockutil as the user as I can simulate that same error:

# sudo -u dockutil --add           
sudo: unrecognized option `--add'

Seems like it should be getting the logged in user since it is shown in the echo output so I don't know why it isn't.

You might try echoing the sudo commands.

Since this is really a scripting/sudo issue unrelated to dockutil and it is an old issue I'm going to close this issue. I'm sorry I couldn't provide a timely response.