How to Remove Specific Apps from The Dock

Im just starting out and have only created a few AppleScripts so far but im creating one to remove MS Office 2011, the only thing im having trouble with is trying to remove the MS Office apps from the dock.

How do i script the removal of specific apps from the dock?

Thanks for any help

The System Events dictionary is scant on functionality for Dock:

You could also manipulate the com.apple.dock.plist in ~/Library/Preferences also

Not sure what else you could do.

As far as I know, you must edit the preference file
~/Library/Preferences/com.apple.dock.plist
You will have to search in the array named persistent-apps the item whose bundle-identifier of tile-data is the MS Office one.

Maybe you may use GUI Scripting to mimic the manual removal. I assume that it wouldn’t be easy if - like me - you asked the Dock to autohide itself.

Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) mercredi 13 janvier 2016 15:16:31

It seems that I got it and it works also when the Dock is autoHiding.

set whichApp to "Hexedit" # EDIT to fit your needs

set the_App to application id ("com.apple.dock")
set path2app to path to the_App as text

set OPTIONS_loc to localized string "OPTIONS" from table "DockMenus" in bundle (path2app as «class furl») --> "Options"
set REMOVE_FROM_DOCK_loc to localized string "REMOVE_FROM_DOCK" from table "DockMenus" in bundle (path2app as «class furl») --> "Supprimer du Dock"
-- set KEEP_IN_DOCK_loc to localized string "KEEP_IN_DOCK" from table "DockMenus" in bundle (path2app as «class furl») --> "Garder dans le Dock"

tell application "System Events" to tell process "Dock"
	set frontmost to true
	-- class of UI elements --> {list}
	tell list 1
		--class of UI elements --> {UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element}
		set found to false
		repeat with anUIelement in UI elements
			try
				tell anUIelement
					set found to value of attribute "AXTitle" is whichApp
					if found then exit repeat
				end tell
			end try
		end repeat
		if found then
			tell anUIelement
				-- name of actions --> {"AXPress", "AXShowMenu", "AXShowExpose"}
				perform action "AXShowMenu"
				tell menu 1
					-- name of menu items --> {"iBooks", missing value,"Options", missing value, "Afficher toutes les fenêtres", "Masquer", "Masquer les autres", "Quitter", "Forcer à quitter"}
					click menu item OPTIONS_loc
					tell menu item OPTIONS_loc to tell menu 1
						-- name of menu items --> {"Garder dans le Dock", "Ouvrir avec la session", "Afficher dans le Finder"}
						--> {"Supprimer du Dock", "Ouvrir avec la session", "Afficher dans le Finder"}
						set maybe to name of menu item 1
						if maybe is REMOVE_FROM_DOCK_loc then
							click menu item 1
						else
							# The first item is KEEP_IN_DOCK_loc, is it checked ?
							--name of attributes of menu item 1 --> {"AXRole", "AXRoleDescription", "AXParent", "AXEnabled", "AXPosition", "AXSize", "AXTitle", "AXHelp", "AXSelected", "AXMenuItemCmdChar", "AXMenuItemCmdVirtualKey", "AXMenuItemCmdGlyph", "AXMenuItemCmdModifiers", "AXMenuItemMarkChar", "AXMenuItemPrimaryUIElement", "AXFrame"}
							if value of attribute "AXEnabled" of menu item 1 is true then click menu item 1
						end if
					end tell # menu item.
				end tell # menu 1
			end tell # anUIelement
		end if
	end tell # list 1
end tell

edit #1 : I added a couple try . end try because here, one UI element has no title and trying to get it issue an error.
edit #2 : no longer use an index when looping upon UI elements.

Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) mercredi 13 janvier 2016 18:48:23