Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using OS X 10.6.4 and am trying to set a folder to automatically enable execute permissions on new script files copied or created in a directory. I have used Sandbox 2 to set every permission for the folder to enabled with sticky bits and the inherit flag set but I still have to manually set the execute flag using chmod for every new flag.

I've done:

chmod -R a+rwxs ~/scripts

I've done:

chmod 7777 ~/scripts

And the permissions for the folder show as:

drwsrwsrwt+ for the folder.

But if I add a new script file it's set to -rw-r--r--+ (the default)

I looked at setting unmask 000 in the .profile file but the default value for files is 666 with an unmask of 022 so that's not relevant since I would need a default value of 777 for files.

I have figure out how to use chmod in an AppleScript triggered by a folder action to automate this but I'm wondering if there is a simple ACL or chmod setting I'm missing.

So, is there a way to automatically set execute permission for new files? (Without using a folder action and AppleScript?)

share|improve this question
add comment

1 Answer 1

OK, I thought I'd give it a few days to see if there was a more sane way to do this. So, here is the AppleScript I created to automatically set any file to executable. It's not perfect though, like if you have a folder with a weird name, e.g. "Scripts, Ruby", it won't work but it's a good start for anyone wanting this functionality.

You need to copy this text to an AppleScript then copy that script file to your Folder Action Scripts directory (~/Library/Scripts/Folder Action Scripts or /Library/Scripts/Folder Action Scripts). Then right click on the folder you want to add the script to, choose "Folder Actions Setup..." and choose this script out of the list.

I've got a much more complicated version that does stuff like updates itself, only allows certain file types to be changed on a per folder basis, allows you to use any username and password to set permissions, and sends growl notifications but I wanted to keep it simple so the solution wasn't obfuscated by the fancy bells and whistles.

Anyway, hope this helps someone else trying to do the same thing.

-- Set all the files in the directory to executable
on adding folder items to currentFolder after receiving addedItems
  try
    -- Set execute permissions for each file that is copied to this directory
    repeat with anItem in addedItems
      tell application "Finder"
        try
          -- Test to see if it's a file or folder (we ignore folders)
          set fileType to type identifier of (info for anItem)
          -- It's a file so change the permissions to execute
          do shell script "/bin/chmod u+x " & (the POSIX path of anItem)
        on error
          -- It's a folder so do nothing
        end try
      end tell
    end repeat

  on error errorStr number errorNumber
    -- Let the user know there was an error
    display dialog errorStr & return & return ¬
      & "Error Number: " & errorNumber ¬
      buttons {"OK"} default button 1 ¬
      with title "Error: " giving up after 30
  end try
end adding folder items to
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.