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
Same answer more or less:
#!/bin/bashcd ~/Librarycurrentuser=($whoami)chown -R $currentuser ~/Library/.monochmod 755 ~/Library/.monoexit 0save the above in a text file and rename it: permissions.sh
then in terminal, navigate to where ever you saved that file and run:
sudo chmod a+x /path/to/permissions.sh
Then, in Finder, right-click your file and select "Open with" and then "Other...".
-------------------------------------------------------------------------------------------------------------------
line by line breakdown:
#!/bin/bash
cd ~/Library #navigates to the current user library
currentuser=($whoami) #defines whomever is running the script as 'currentuser' (note that if you're running this for other users, the only thing you'd need to do is specify the username instead where it says $currentuser below
chown -R $currentuser ~/Library/.mono
#grants ownership (implied Read/write) for <user> on folder: ~/Library/.mono
chmod 755 ~/Library/.mono #grants (owner can read and write) permissions on the folder
exit 0 #exits the script cleanly and returns to finder.
what's 755 mean --> crash course on permission blocks:
User/Group/Everyone
so 755 means owner has read/write/execute, group has read and execute, and everyone else also has read/execute
You can customize this to something closer to 700, which is owner can do whatever and nobody else can touch the folder, but that's up to you.
group by default is probably root or wheel (sudoers).