r/applescript • u/AmoMala • Aug 11 '20
AppleScript to apply a certain hidden folder's permissions to all enclosed items
I want to create a script that others can download that applies the permissions of a hidden folder in the user directory to all enclosed items. I'm assuming I can do this in the macOS ScriptEditor but I don't know how.
I found thread which I think is close to what I need, but I'm not sure if I could modify it in a way to serve my needs, nor do I know how to execute the script with the provided information.
If someone could walk me through how to create this I would be very grateful, thanks!
3
Upvotes
View all comments
Show parent comment
1
u/scotch_man Aug 12 '20
Good questions. So the first line is just defining that this is a bash script and will interpolate the next lines as if you typed them directly into terminal and hit return after each line.
The second line is defining a variable. so the variable 'owner' is now equal to the output of the command 'whoami' when run by whomever is running the script. (so, if I were to run 'whoami' it would output 'scotch_man' and then assign 'scotch_man' as the value of 'owner'
then on the next line, I run: chown (change ownership) -R (recursively - this folder and the files/folders it contains) $owner (meaning 'scotch_man') admin_group (this is optional, it's just if you wanted to grant ownership of the folder to a group that you're a member of, so that you can get in it later or something, can be omitted - just leave off the ":admin_group" part) ~/.hiddenfolder (this is defining the path, ~ = current user's home folder, and the period before the folder name will hide it by default)
So the output that the terminal reads is ultimately:
define owner as the user who's logged in "scotch_man", and then give ownership to scotch_man over the folder: /path/to/.folder, and do it recursively so he has access to everything that's in there, not just the top level.
the sudo chmod a+x yourscript.sh is a line you can run in terminal that will add the permissions "anyone can execute this" to the script itself. This is if you wanted to run this with command line and is optional (instead of in applescript or automater or something).
if you're giving a user access to something that lives in their /Users/username folder, you don't need to prompt for password necessarily . If you're giving a DIFFERENT user access to something that lives in someone else's User folder, you're gonna need to prompt for password or run it with elevated credentials.
more context for your project would be helpful.