Read permissions for a file/folder

Hello All,
I want to create a script where I can copy permissions from one item, be it a file or folder, to another item. For example, I want to copy the permissions and ownership from the printers.conf file in /etc/cups/ to a file on my desktop.

I’m having a problem Getting/Reading permissions from items. I could use “do shell script” issuing “ls -lan” plus the path of the item, and then delimiting the result to obtain the permissions and ownership. However, this seems problematic when trying to obtain the information for a folder, for example, let’s say I want to get the permissions and ownership for a folder called “mark” on my desktop. Issuing “ls -lan ~/Desktop/mark” will list the contents of the folder. So, it would work for a file, but not for a folder.

I am aware that I could use the “Get X’s privileges of Y” command in a Tell Finder block, however there is one issue with this, unless I’m missing something, and it is that this does not return the executable portion of the permission block, and does not allow me to set this either. Thus I would not be getting the complete permissions block for the item.

Is there another shell/applescript command I could use to obtain the complete permission and/or owner information for a file and folder?

Thanks in advance for any help.

Read this post:

There are several other posts you mind find useful as well. Do a search here on MacScripter for ‘Permissions’.

Cheers,

Craig

Hi,

I wrote a little command line foundation tool named privileges, which displays owner, group and permissions CR separated.
Save it where ever you want and use it in AppleScript with


set d to "/etc/cups/printers.conf"
set {_owner, _group, _permissions} to paragraphs of (do shell script "/path/to/privileges " & d)