AppleScript to set ownership permissions?
apple Verified ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hello,
does anyone know (or better have) how to make an AppleScript that change/set the ownership permissions of a folder (and all enclosed files and folders) to Owner=root:RWX, Group=admin:RWX?
Thank you
Jerome
5 replies
Sign in or join Beachball Help to reply.
- 0
Camelot ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
This is easily done via 'do shell script'
set
thePath
to
quoted form
of
POSIX path
of (
choose folder)do shell script "chmod -R 770 " &
thePath
with
administrator privilegesdo shell script "chown -R root:admin " &
thePath
with
administrator privileges - 0
Jerome Curty ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi Camelot,
thank you for your message but i'm a new user of AppleScript (in fact I try it to help me to solve permissions problems)...
Just a question concerning your answer, I seems that I need to choose a folder but I only want to drag and drop a folder on this AppleScript and it work without any user operation. Is it possible? Sincerely I don't understand all functions in AppleScript.
Thanks,
Jerome - 0
Camelot ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I only want to drag and drop a folder on this AppleScript
OK, that's possible. You need to wrap the entire script in an 'on open' handler so that it's called when items are dropped on the script:
on
open
theseItemsset
theItem
to
item 1
of
theseItems --
extract the first itemset
thePath
to
quoted form
of
POSIX path
of
theItem --
get its pathdo shell script "chmod -R 770 " &
thePath
with
administrator privilegesdo shell script "chown -R root:admin " &
thePath
with
administrator privilegesend
openNote that this now needs to be saved as an application in order to be used as a droplet - you can't drop files/folders on a document.
The issues here are that 'on open' always passes a list of items, even if there's only one selected, so the first line extracts the first item from that list.
You might want to change that. For example, would you ever want to drop multiple items on the script and have them all change?Other than that, the script is pretty much the same. Note that there are no checks here to ensure you drop a folder on the script - a file would work just as well. You'll have to decide whether that's a problem for you or not.
- 0
Jerome Curty ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi "Camelot",
just this message to thank you: u help me so much. I have just add after "with administrator privileges" password "" for not having the pop-up menu.
Thanks a lot,
regards,
Jerome - 0
Jay Louvion ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi there Cam,
On the same kind of subject, the "with administrator privileges" will prompt for a password, right ? And if I don't want a dialog, I can implement the password in my scpt;
What on earth is happenng when the run script returns "Finder got an error: a privilege violation occured" ? The files I am trying to copy are to the /sbin/ folder. I cann do that using sudo, but how do I AS it ?
So far, so good:
tell application "Finder"
set myFolder to (container of (path to me)) as string
set SetFile to quoted form of POSIX path of ((file "SetFile" of folder myFolder) as string)
set GetFileInfo to quoted form of POSIX path of ((file "GetFileInfo" of folder myFolder) as string)
try
do shell script "cp " & GetFileInfo & " /sbin/GetFileInfo" with administrator privileges
do shell script "cp " & SetFile & " /sbin/SetFile" with administrator privileges
do shell script "chmod a+sx /sbin/GetFileInfo" with administrator privileges
do shell script "chmod a+sx /sbin/SetFile" with administrator privileges
do shell script "mkdir -p /Developer/tools/" with administrator privileges
do shell script "cp " & SetFile & " Developer/tools/SetFile" with administrator privileges
do shell script "chmod a+sx /Developer/tools/SetFile" with administrator privileges
on error mistake
display dialog mistake
end try
end tellTIA,
J.