Enable write flag on Drop Box files via Folder Actions

Jan 05, '10 07:30:00AM

Contributed by: renaultssoftware

Generally, when files are dropped in your ~/Public/Drop Box you can only read them. You have to save a copy if you edit it. I wanted a script that would enable writing and that moved them to your desktop. So I wrote a Folder Action that let me do both things. If I could not enable them because of limitations, I want a sudo (SuperUser Do) to be used.

Here is my AppleScript to do this:

on adding folder items to thisFolder after receiving theseItems -- create list of files & folders
  try -- in case you can't due to limitations
    repeat with thisItem in theseItems -- take a file to repeat with
      set thisPath to quoted form of POSIX path of thisItem -- puts the shell path in quotes for ease of use
      set thisCommand to "chmod u+w " & thisPath -- the command
      do shell script thisCommand -- execute the file
    end repeat
    move theseItems to desktop
  on error
    repeat with thisItem in theseItems -- same except with sudo
      set thisPath to quoted form of POSIX path of thisItem
      set thisCommand to "sudo chmod u+w " & thisPath
      do shell script thisCommand with administrator privileges -- added the sudo part
    end repeat
    move theseItems to desktop
  end try
end adding folder items to
[robg adds: To use this, save the script in your user's Library » Scripts » Folder Action Scripts folder, and then attach it to your Drop Box folder as a Folder Action. In 10.5, Control-click on the Drop Box folder and select More » Attach a Folder Action from the contextual menu; in 10.6, choose Folder Actions Setup from the contextual menu. I haven't tested this one. Also note this hint, which explains Drop Box folder permissions in a clear and easy-to-understand manner.]

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20091229093022967