Compressing of Files (or Folders containing them) with resource forks.

A MacOSXhints.com hint recently dealt with the inability of zip to deal with resource forks in files that had them or folders that contained files that had.

This is the hint reduced to AppleScript:

to TarFile(toTar, putHere) -- compresses an object INCLUDING its resource fork, given alias paths
	set tName to name of (info for toTar) -- toTar is a path
	set toTar to quoted form of POSIX path of toTar
	set putHere to quoted form of POSIX path of putHere -- path to container of compressed file
	try
		return paragraphs of (do shell script "/usr/bin/tar cjvf " & putHere & tName & ".tbz " & toTar)
	on error
		return false
	end try
	-- returns posix path of objects that were compressed, or if compression fails, returns false
	-- the ._name files are the resource forks, if any.
end TarFile

to UnTarFile(tbzFile) -- uncompresses a tbz file including attaching the resource forks of the files.
	if name extension of (info for tbzFile) is "tbz" then
		try
			return (do shell script "/usr/bin/tar xjvf " & quoted form of POSIX path of tbzFile)
		on error
			return 0
		end try
	else
		return 1
	end if
	-- returns path to untarred objects, or 0 if decompression fails, or 1 if original was not a tbz file
end UnTarFile

-- In the following, substitute your own file or folder...

set tarThis to alias ((path to desktop folder as text) & "FracMath:") -- file or folder
set putHere to (path to desktop folder) -- container
set TBZ to TarFile(tarThis, putHere)
-- TBZ is posix path to objects that were compressed where "._name" files are resource forks.

-- and to uncompress the archive...
--Move tarThis, comment the tarThis line and the TBZ line, and uncomment the following.

(*set wasTarred to alias ((putHere as text) & "FracMath.tbz")
set tFiles to UnTarFile(wasTarred)*)

It’s worth noting here that TAR doesn’t have the resource-preserving feature before Mac OS 10.4.x