On Jul 30, 2008, at 3:14 PM, Jim Weisbin wrote: I'm probably re-inventing the wheel here, but I wrote this because of difficulties with POSIX permissions using Leopard server - seems that files copied from a client to the server lose their group permission to write and become read-only. However, if you copy them to your desktop first and change the group and everyone to read-write, then copy them back to the server, they have the correct permissions for that share point. So this takes a folder and makes it's contents entirely read-write for everyone. The folder MUST be on the user's desktop (don't want to screw up permissions on the rest of the system!), and root user must be enabled. My question is about the cd command in the shell script. Theoretically, if I cd to that folder, I can just do "chown -R *" instead of "chown -R " & path_to_folder
But that scares me - how do I know I really cd'd there? If not, the chown -R * could be very very bad!
do shell script "cd " & f1 & "; chown -R " & userHome & " " & f1 & "; chgrp -R staff " & f1 & "; chmod -R ugo=rwx " & f1 user name "root" password my_pass with administrator privileges
First off, "chown -R me foo" is not quite the same thing as "cd foo ; chown -R me *" -- the first includes the directory "foo" in the chown, the second does not. The real equivalent would be "cd foo ; chown -R me .". Not that this is really any less scary, which brings us to the "how do I know the cd command worked?" part. sh (unlike AppleScript) will cheerfully continue running script statements even if one of them fails (for some definition of "fail", namely that it returns a non-zero status). The trick is to use a conditional. There's "if", of course, but for one-liners it's easier to use "&&" and "||": the first runs the right-hand side only if the left-hand side succeeded, the second only if it failed. To group a sequence of statements, put them in parentheses. For example, your statement would look something like this:
cd foo && ( chown -R me . ; chmod -R a=rwx . )
As a side note, it's really really bad security practice to ask for someone's admin password in your own dialog. It's not necessary in any case -- the "admin" of "with administrator privileges" can do a chown just as well as root can, so you can drop the "user name" and "password" parameters, and let "do shell script" get the password for you.
--Chris Nebel AppleScript Engineering
|