Simple Duplicate/Overwrite AppleScript

I am trying to create an Apple Script so that the com.apple.dock.plist file is overwritten by one of my choice, then the dock restarts. every-time a user logs in. This way I can keep the docks looking the same computer to computer.

This is what I am trying, but nothing is happening
tell application “Finder”

duplicate file “source file here?” to folder “What would I put here so the current users com.apple.dock.plist is overwritten by the one of my choice”
replacing
true

end tell

Should I also be employing something like this?

set CurrentUser to do shell script “whoami”

set ThePath to “/Users/” & CurrentUser & “/Library/Preferences/”

Basically I need my com.apple.dock.plist to be overwritten to users/currentuser/library/preferences -so first I need the current user to be found

Sorry this is a very beginner-ish question. I am new to Apple script.

Thanks!

Hi,

try this

set userPrefFolder to path to preferences -- the preferences folder of the current user
set myDockPrefs to (choose file without invisibles)
quit application "Dock"
tell application "Finder" to duplicate myDockPrefs to userPrefFolder replacing yes
launch application "Dock"

I feel so newbish for asking this question

Will using the “userpreffolder” section copy the file to the current users preferences regardless of what user just logged in? I want this script to be universal as it will be deployed in a lab situation

The path to preferences portion, would I put somethings like /users/ … or?

Thank you!

Yes, path to preferences points always to [startup disk]:Users:[current user]:Library:Preferences:

I don’t however want to write a script for each user. I need it to be universal as it will run at startup, or am I missing something in your explanation?

What part of this script should I be actually editing?

the script is universal, it works regardless of the name of the startup disk and the name of the current user

Stefan,

I think the “choose file” portion might be a problem, since he’s wanting this to run mostly “hands off” for the user. However, he probably has a known place for the dock prefs he wants to install, that’s simple enough to edit and change.

itsallinurhead,

You’re making it harder than it has to be. Trust Stefan, he’s a good scripter and knows what he is talking about. :slight_smile:

Sorry, my questions are quite stupid. Yes, I do have a set location for the dock prefs. I was going to put them in a place available to all users, but make it not editable.

Kevin, will what you said be a problem, or will this indeed run hands off?

Hi,

I recommend to save the script as application bundle,
then open its package folder with the contextual menu > Show package contents
and put your reference file com.apple.dock.plist into the folder Contents:Resources:
This modified script copies the file from the mentioned place into the preferences folder of the current user

set userPrefFolder to path to preferences -- the preferences folder of the current user
try
	set myDockPrefs to ((path to me as Unicode text) & "Contents:Resources:com.apple.dock.plist") as alias
	quit application "Dock"
	tell application "Finder" to duplicate myDockPrefs to userPrefFolder replacing yes
	launch application "Dock"
on error
	display dialog "Preference file couldn't be found" buttons {"Cancel"} default button 1
end try

That’s a good approach, Stefan. It keeps it all in one spot and makes (reasonably) sure that the users can’t fiddle with the file.

Could I just add this to the end of that script? I am using a program that edits the loginwindow file so all these scripts run when the user first logs in, but it only allows me to run one script.

tell application “Finder”
try
mount volume “smb://ls1-mach/USERS$/”
end try
end tell

[This mounts the community shared drive]

So I got the script to work, and runs perfectly fine within OS X, but I can not get it to run when the system boots

I added it to loginwindow using

sudo defaults write com.apple.loginwindow LoginHook /library/login.app

What am I doing wrong?

the argument of LoginHook should be a shell script, not an AppleScript application
You can e.g. create a shell script like this

#!/bin/sh osascript path/to/script.scpt
make it executable (with chmod) and attach it to the LoginHook

Stefank,

Thank you!

Can I use

#!/bin/sh
osascript path/to/script.scpt

More than once in the shell script I create? I ask so I can just launch the different scripts I have created rather then figuring out how to combine them and having to ask further questions.