I am trying to get an applescript written which will prompt the user for the “Master” library folder, then prompt the user for the location of the users folders, then copy the library folder into those users folders. I have all this working ok, but now i need to somehow set the permissions on those library folders correctly…
Here is my script so far:
tell application "Finder"
-- First, get user to select the master library folder
set LibraryMaster to choose folder with prompt "Please select master library folder"
-- Now, get user to select location of the Users home folder
set userFolder to choose folder with prompt "Please select Users folder"
-- Now get the list of user folder in that location that start with 0
set listOfFolders to every folder of userFolder whose name starts with "0"
-- for every folder in the selected users folder...
repeat with aFolder in listOfFolders
select LibraryMaster
-- Copy the library master folder into the user folder
duplicate selection to aFolder with replacing
end repeat
--set listofUsers to do shell script "find " & LibraryMaster & " -name 0* -maxdepth 1 -print"
end tell
The last do shell script line was my attempt to get every users shortname so I could run the chmod command on the folder… but it got a bit complicated… any suggestions would be welcome.
So basically now, all I need is to go through the user folders in the listOfFolders list and modify the ownership of the library folder to the correct owner.
Thanks
First of all: why let the user choose the library folder? Try this:
tell application "System Events"
set librarySystem to path to library folder of system domain
set libraryUser to path to library folder of user domain
end tell
Changing ownership: the best way is to do this with a unix command, like this:
repeat with thisFile in theseFiles
do shell script "chmod -R 777 " & quoted form of POSIX path of thisFile -- makes it readable/writable/executable
end repeat
I am guessing that the “Master” library is a separate folder constructed in advance by fherbert.
JanGeerling: I’ve got two problems with your scripts.
First up, the first one uses incorrect syntax. Try this instead:
set librarySystem to path to library folder from system domain
set libraryUser to path to library folder from user domain
The second one changes the permission modes, not the owners.
Assuming the users’ short names are identical to that of their home folder, try something along the lines of this (warning: untested):
set masterLibrary to choose folder with prompt "Please select master library folder:"
set usersFolder to path to users folder -- Assuming users folder is /Users/
tell application "Finder"
set userFolderList to every folder of usersFolder whose name starts with "0"
set usersFolder to POSIX path of usersFolder
set masterLibName to name of masterLibrary
repeat with thisUser in userFolderList
duplicate masterLibrary to aFolder with replacing
set userName to name of thisUser
do shell script "chown -R " & userName & space & quoted form of (usersFolder & userName & "/" & masterLibName)
-- Could also do a chmod here.
end repeat
end tell
Excellent, thats exactly what I wanted - I did mistakingly say that I wanted to chmod instead of actually wanting to chown the library folder… and yes, I have a master library folder created in advance. I would still like to prompt the person running the script for the locaton of the users home folder, as it may not be in the standard location.
I guess the bit I really needed was finding the short name of the user from the path of their home folder … ie
the command:
name of thisUser
was the little bit I really needed to find out.
Thanks very much for your help.
EDIT: I also needed to modify the line:
do shell script "chown -R " & quoted form of (usersFolder & name of thisUser & "/" & masterLibName)
to be …
do shell script "chown -R " & name of thisUser & " " & quoted form of (usersFolder & name of thisUser & "/" & masterLibName)
I had a similar idea, but I know exactly where the files are kept on the server and where they belong on each Mac. I wrote this script and saved it as an app in the library/scripts folder. The user selects it from the script drop-down (needs to be activated in the AppleScript utility) and it deletes the current script set, then copies the server set to the local Mac. I am sure you can adapt it to your needs. I wanted a process that was mostly invisible to the user. So far, it works well. I am sure I will change bits in the future, but for now simple works best.
Levon
tell application "Finder"
set scriptFolder to "Macintosh HD:Library:Scripts"
set scriptFoldercontents to every item of folder "Macintosh HD:Library:Scripts"
set DPSSScriptsContents to every item of folder "Macintosh HD:Volumes:DPSS Administration:AppleScript Central:DPSS Scripts:"
set DPSSScripts to "Macintosh HD:Volumes:DPSS Administration:AppleScript Central:DPSS Scripts:"
set DPSSScriptsFolders to every folder of folder "Macintosh HD:Volumes:DPSS Administration:AppleScript Central:DPSS Scripts:"
delete scriptFoldercontents
duplicate contents of DPSSScriptsContents to scriptFolder with replacing
display dialog "Your AppleScripts are now up to date."
end tell
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)
this should do the same, but still more invisible than involving the Finder
set source to quoted form of "/Volumes/DPSS Administration/AppleScript Central/DPSS Scripts/"
set destination to quoted form of POSIX path of (path to scripts folder from local domain)
do shell script "rsync -atE --delete " & source & space & destination
display dialog "Your AppleScripts are now up to date."
I like the idea of keeping the Finder out of the process, but I get a ‘file has vanished’ error in SD4 when running this one. I am always a bit nervous when running shell scripts.
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)
I updated it to separate a few scripts that broke when being replaced. They now live in the user Scripts folder. They are only copied the first time if they do not exist. I am sure it could be simpler and quicker, but it meets my needs and works on all my managed Macs.
Levon
tell application "Finder"
mount volume "afp://my server"
set userScripts to (path to home folder as Unicode text) & "Library:Scripts"
set DPSSUserScriptsContents to every item of folder "Macintosh HD:Volumes:DPSS Administration:AppleScript Central:AppleScript User Scripts:"
set scriptFolder to "Macintosh HD:Library:Scripts"
set scriptFoldercontents to every item of folder "Macintosh HD:Library:Scripts"
set DPSSScriptsContents to every item of folder "Macintosh HD:Volumes:DPSS Administration:AppleScript Central:DPSS Scripts:"
set DPSSScripts to "Macintosh HD:Volumes:DPSS Administration:AppleScript Central:DPSS Scripts:"
set DPSSScriptsFolders to every folder of folder "Macintosh HD:Volumes:DPSS Administration:AppleScript Central:DPSS Scripts:"
delete scriptFoldercontents
duplicate contents of DPSSScriptsContents to scriptFolder with replacing
try
duplicate contents of DPSSUserScriptsContents to userScripts without replacing
end try
display dialog "Your AppleScripts are now up to date."
end tell
Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)