r/applescript • • 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

5 comments sorted by

View all comments

Show parent comment

1

u/AmoMala Aug 12 '20

more context for your project would be helpful.

I haven't read the whole reply yet, but I wanted to give this to you now in case it changes anything else you've said.

I consistently deal with a program that crashes as a result of the user account not having permissions to a file/folder inside the .mono folder which is located (in my scenario) in the user's Library directory. Development has not seen it fit to add a layer of permissions check and sign in to fix this particular problem. I know I could do this at the terminal level, but I thought it would be nice to have a script to distribute that fixes the problem easily.

Right now I. . .

  1. Use Terminal to show all files and folders.
  2. Navigate to the user's Library directory.
  3. Right-click the .mono folder and bring up the information window.
  4. Click the padlock and have the user sign in.
  5. Click the user account in the permissions table, and force the read & write permissions on all enclosed items.

1

u/scotch_man Aug 12 '20

Same answer more or less:

#!/bin/bash

cd ~/Library

currentuser=($whoami)

chown -R $currentuser ~/Library/.mono

chmod 755 ~/Library/.mono

exit 0

save 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...".

  • Here you select the application you want the file to execute into, in this case it would be Terminal.
  • Double-clicking the file will now execute it.
  • Whoever double-clicks it will have their version of .mono inside their /Users/username/Library folder updated for them.

-------------------------------------------------------------------------------------------------------------------

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

PermissionsNo permissionExecuteWriteWrite and executeReadRead and executeRead and writeRead, write and execute
Octal Notation01234567
Symbolic notation-----x-w--wxr--r-xrw-rwx

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