How to create a Folder Action Script to tar items dropped in folder

applescriptfoldersscripttar

I would like to drop/copy files/folders and have them compressed then copied to my desktop. This is what I know so far… and it isn't much so any help would be appreciated.

on adding folder items to theFolder after receiving theAddedItems
repeat with x in theAddedItems

This will create my list of files dropped into the folder. Now my compression command…

tar cvf - *variableForFileListHere* | gzip -9 - > files.tar.gz

Somehow I know I have to feed the list "theAddedItems" created in the first part of the script to the tar command. But I'm clueless as to how this might be done. Reading now about tar and it's options as I'm sure there is an "include" function for pointing to a list of items to add to the archive.

Best Answer

Try:

on adding folder items to theFolder after receiving theAddedItems
    set myList to {}
    repeat with x in theAddedItems
        set end of myList to quoted form of x's POSIX path & space
    end repeat
    set myList to text 1 thru -2 of (myList as text)
    do shell script "tar cvf " & myList & " | gzip -9 - > ~/Desktop/files.tar.gz"
end adding folder items to