I have created a dock under an admin login on an iMac and the people want the same dock for all users.
I have tried copying the .plist over but to no avail. All I can find on the internet is that it seems to work up to High Sierra but not past it.
Has someone written a script that makes this happen for Catalina?
Thanks
Model: iMac
AppleScript: 2.7
Browser: Safari 537.36
Operating System: macOS 10.14
Hi.
Interesting question. I don’t know if my idea bellow is the best solution.
Exists some scripts on this site in AppleScriptObjC, which successfully adds and removes dock items. On the new systems too.
Now, the rest:
I think, you need create 1 new shared text file at /Users/Shared/ location. For example, /Users/Shared/DockItemsList.txt. The administrator should be able to write into this file. The other users should be able only read from it.
Then, you write 1 script, which gets administrator dock items list and writes them to shared text file. This script you can make administrator’s startup item.
Here is one sample script 1:
-- GET DOCK APP ITEMS
set pListpath to ((path to preferences) as Unicode text) & "com.apple.dock.plist"
tell application "System Events" to tell property list file pListpath to tell contents
set dockAppList to value of property list item "file-label" of property list item ¬
"tile-data" of property list items of property list item "persistent-apps"
end tell
-- WRITE THE LIST TO SHARED TEXT FILE
set theFile to "Users:Shared:DockItemsList.txt"
set theText to ""
repeat with anApp in dockAppList
set theText to theText & anApp & return
end repeat
set theOpenedFile to open for access file theFile with write permission
set eof of theOpenedFile to 0
write theText to theOpenedFile
close access theOpenedFile
Then, you write one second script, which clears user’s dock, then reads dock items list from shared text file and adds them to user’s dock. This second script should be the startup item for every user.
Sample script 2.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set sharedTextFile to alias "Users:Shared:DockItemsList.txt"
set adminDockAppList to paragraphs 1 thru -2 of (read sharedTextFile)
set pListpath to ((path to preferences) as Unicode text) & "com.apple.dock.plist"
-- REMOVE USER's DOCK APPs NOT ALLOWED BY ADMINISTRATOR
tell application "System Events" to tell property list file pListpath to tell contents
set userDockAppList to value of property list item "file-label" of property list item ¬
"tile-data" of property list items of property list item "persistent-apps"
end tell
repeat with appName in userDockAppList
if not (appName is in adminDockAppList) then my removeDockItem(appName)
end repeat
-- ADD ABSENT ADMINISTRATOR DOCK ITEMs to USER's DOCK
tell application "System Events" to tell property list file pListpath to tell contents
set userDockAppList to value of property list item "file-label" of property list item ¬
"tile-data" of property list items of property list item "persistent-apps"
end tell
repeat with appName in adminDockAppList
if not (appName is in userDockAppList) then
set anApp to application appName
set appPath to POSIX path of (path to anApp)
my add_item_to_dock(appPath)
delay 0.5
set isRunning to anApp is running
if isRunning then
delay 0.5
quit anApp
end if
end if
end repeat
-- HANDLERS
on removeDockItem(dockItemName)
set dockItemName to current application's class "NSString"'s stringWithString:(dockItemName)
set userDefaults to current application's class "NSUserDefaults"'s standardUserDefaults()
set dockDict to (userDefaults's persistentDomainForName:("com.apple.dock"))'s mutableCopy() -- Seems to be mutable anyway.
set apps to (dockDict's valueForKey:("persistent-apps"))
if (apps's |count|() > 0) then
set filter to current application's class "NSPredicate"'s predicateWithFormat:("%K != %@") argumentArray:({"tile-data.file-label", dockItemName})
set appsCopy to apps's filteredArrayUsingPredicate:(filter)
if (appsCopy's |count|() < apps's |count|()) then
try
tell application "Dock" to quit
end try
tell dockDict to setValue:(appsCopy) forKey:("persistent-apps")
tell userDefaults to setPersistentDomain:(dockDict) forName:("com.apple.dock")
try
tell application "Dock" to activate
end try
end if
end if
end removeDockItem
on add_item_to_dock(item_path)
try
tell application "Dock" to quit
end try
do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & item_path & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
try
tell application "Dock" to activate
end try
end add_item_to_dock
I updated my first post here. The script 1 is ready to use. The script 2 is ready too, it works, but I see it can be improved. Any suggestions for improvement are welcome.
Thank you for your help. I will try it out next week.