AppleScript to set ownership permissions?

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

Posted on Aug 31, 2005 10:47 AM

Reply
5 replies

Aug 31, 2005 11:29 AM in response to Camelot

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

Aug 31, 2005 11:50 AM in response to Jerome Curty

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 theseItems

set theItem to item 1 of theseItems -- extract the first item

set thePath to quoted form of POSIX path of theItem -- get its path

do shell script "chmod -R 770 " & thePath with administrator privileges

do shell script "chown -R root:admin " & thePath with administrator privileges

end open

Note 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.

Sep 28, 2005 4:47 AM in response to Camelot

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 tell

TIA,

J.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript to set ownership permissions?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.