Apr 282010
 

I have a problem. I complicate things in order to simplify them. wxBlogger began that way, as did wxCURL, as did wxSync. Each began with the idea of simplifying some of the more mundane tasks that I do each day. Since I began working with Unity 3D, I’ve found on several occasions that using Mac OS X’s built-in right-click “Compress …” did strange things, particularly with executable files, that would only be discovered by Windows users later. Global Game Jam 2009 this bit us. It’s bitten me several other times.

Now, theoretically, I could open the “Archive Utility” application housed in (/System/Library/CoreServices/) and change its preferences, instructing it to use the more Windows friendly “ZIP” format rather than… Well, whatever it does and calls “.zip”. But, that would be simple, right? What would be interesting about that solution?

Thus I taught myself a little Apple Script and whipped up what I’ve called “WinZip,” which is clearly not this WinZip. My little deal is a Mac App / Apple Script that does the work of making a Windows compatible ZIP file for you without having to know the commands or do it yourself in the Terminal. The source code and application are all released under the wxWidgets License.

-- WinZip for Mac OS X
-- Casey O'Donnell
-- http://www.caseyodonnell.org/
-- This script takes a dropped file (or several) and compresses them in a Windows
-- compatible format using the "ditto" command.
--
-- The source and the application are released under the wxWidgets Licence, which
-- can be found here: http://www.wxwidgets.org/about/newlicen.htm
on open fileList
	set szPathName to ""
	set szPathDest to ""
	repeat with i in fileList
		set szPathName to quoted form of POSIX path of (i as text)

		set iLength to length of szPathName
		set szLastChars to get characters (iLength - 1) thru (iLength - 1) of szPathName

		if (szLastChars contains "/") then
			set szPathDest to get characters 1 thru (iLength - 2) of szPathName
			set szPathDest to szPathDest & ".zip'"
		else
			set szPathDest to get characters 1 thru (iLength - 1) of szPathName
			set szPathDest to szPathDest & ".zip'"
		end if

		tell application "Terminal"
			do script "ditto -c -k -X " & szPathName & " " & szPathDest & "; exit"
		end tell
	end repeat
end open