I would like to set up an automated way for archiving files in OS X Lion. By archiving I mean using HFS+ compression feature on a specific folder, and make every file that I move into this folder automatically compressed. I'm thinking of using this to archive large files that I don't use often, but without having to manually create compressed archives and having to extract them in case I need them.
I came across the tool afsctool (brew install afsctool), which can, via command-line, apply HFS+ compression to a folder and all files in it. But I believe it does not activates compression of future files moved to the folder.
Moving files manually and running a command line instruction repeatedly is inconvenient. Therefore I'm guessing I would need to used automator/AppleScript to execute this in two steps:
- Create a script that allows moving any file to a specific folder. Ideally an option named Archive accessible via right-click on the file.
- Run a command line instruction
afsctool -c <folder>, to activate compression on all new files just moved to the folder.
I have no experience using automator or AppleScript, so I would like to know where to start, especially regarding how to add actions to Finder, and how to run a command line tool from a script.
Updates
@kopischke guide works well. The script itself, I made based on the answer by @mark, but using afsctool -c <folder>, instead of ditto. Here's the script:
It should be put in ~/Library/Scripts/Folder Action Scripts
on adding folder items to this_folder after receiving these_items
repeat with i from 1 to number of items in these_items
try
set this_item to item i of these_items
tell application "Finder"
set the file_name to the POSIX path of this_item
end tell
set cmd to "/usr/local/bin/afsctool -c " & file_name
do shell script cmd
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
end try
end repeat
end adding folder items to
Since afsctool at MobileMe is no longer available, there's diimdeep/afsctool at GitHub, currently 1.6.4.
Also afsctool in MacPorts where they're aware of the MobileMe issue but maybe unaware of the source at GitHub.