09-02-2022 06:51 AM - edited 09-02-2022 07:54 AM
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
09-02-2022 08:51 AM - edited 09-02-2022 08:53 AM
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.
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/
09-02-2022 10:19 AM - edited 09-02-2022 10:27 AM
@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.
Posted on 09-02-2022 10:58 AM
#!/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
Posted on 09-02-2022 11:00 AM
maybe add no restart in there because the killall Dock is doing that
--no-restart
09-02-2022 12:31 PM - edited 09-02-2022 12:31 PM
@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?
Posted on 09-05-2022 01:00 AM
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
Posted on 09-06-2022 08:13 AM
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?
Posted on 09-06-2022 11:22 AM
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.
09-06-2022 07:20 PM - edited 09-06-2022 07:21 PM
@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!