Dockutil - Monterey 12.5.1 - Remove Dock Item

machattan
New Contributor II

 

Hey Everyone, hoping someone can help. we're getting all kinds of crazy errors in JAMF when trying to remove a dock item using Dockutil. Everything from root access to dock item not found, to argument not supported. It can't be this hard, is it? Trying to do this in Monterey on the M1 MBPs. Here's what i've been trying to push out. A simple script. Running it locally works. Am i doing something wrong here:

 

 

#!/bin/zsh

loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
dockutilbin="/usr/local/bin/dockutil"
loggedInUserPlist="/Users/$loggedInUser/Library/Preferences/com.apple.dock.plist"

$dockutilbin --remove file:///Applications/BarcodeForVerification2021/Barcode\ x14.app --restart $loggedInUserPlist


exit 0

 

 

 

 

9 REPLIES 9

Hugonaut
Valued Contributor II

@machattan 

 

I suggest using the Dock Items Payload within a Policy to remove the app.

 

Located in Jamf Pro Dashboard -> Settings -> Computer Management -> Dock Items

 

Add your App as depicted below. Then Create a policy with the dock items payload, select your app that you just added & test removing.

 

Screen Shot 2022-09-02 at 10.49.37 AM.png

If the path shown in your script above is indeed the location of the application, the path will be as follows.

 Path: file:///Applications/BarcodeForVerification2021/Barcode%20x14.app/

 

 

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

machattan
New Contributor II

@Hugonaut Thanks man! Actually, Dock Item was going to be my last resort. I've always been told to refrain from using the Dock Item option in policies. If i do use it, because it worked, how do i make it first or move it up in the policy list of executables? I have to put this all into a Self Service action for users.

bizzaredm
Contributor
#!/bin/zsh

dockutilbin='/usr/local/bin/dockutil'
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
loggedInUserPlist="/Users/$loggedInUser/Library/Preferences/com.apple.dock.plist"

$dockutilbin --remove /Applications/BarcodeForVerification2021/Barcode\ x14.app $loggedInUserPlist

sleep 1

killall cfprefsd                                      
killall Dock

exit 0

maybe add no restart in there because the killall Dock is doing that

--no-restart

machattan
New Contributor II

@bizzaredm Thanks for this! I run the script locally, works! I try to run the script via Self Service (which is where this is all going), no good! SS just sits and spins... thoughts?

KretZoR
New Contributor III

Hi,

Try below. Hope that works out for you! :)

#!/bin/bash

# Get currently logged in user
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }')

# Path to dockutil tool
dockutilPath="/usr/local/bin/dockutil"

/bin/launchctl asuser $(id -u $currentUser) $dockutilPath --remove "/Applications/BarcodeForVerification2021/Barcode x14.app" --no-restart

sleep 1

killall cfprefsd
killall Dock

exit 0

machattan
New Contributor II

Okay, getting closer! Thanks for this @KretZoR ! So now, the policy executes from SS. No more spinning wheel of what the heck?!?! But the Dock items doesn't get removed. I thought maybe it was the Dock item itself, so i tried changing the app to the Books.app. Just to see. Same thing. Dockutil command (--remove) is not removing the Dock item, for whatever reason. Thoughts?

mm2270
Legendary Contributor III

You kind of overcomplicated this by using "file:///Applications/BarcodeForVerification2021/Barcode\ x14.app". It should be as simple as this:

$dockutilbin --remove "Barcode x14.app" --restart $loggedInUserPlist

 Dockutil is flexible in that it can take a full path or bundleid, but just using the label for removing it, meaning how it actually shows up in the Dock when you hover the cursor over it, is often sufficient.

machattan
New Contributor II

@mm2270 I think we may have something here! Combined yours with the above and it seems to be working finally! Now to test with our end users. Thanks again!