Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Oats

macrumors regular
Original poster
Jan 8, 2003
194
1
New York
I created a zip file using OS X, which is meant to be used cross-platform. I unzipped it in Windows, and I see all these ugly .DS_store and __MACOSX folders. I do not want these hidden files in my ZIP, since they are not hidden or useful for Windows.

Any tools or options I can use to not include these files when creating a ZIP?
 
Use this Applescript in an Automator workflow and save the plug-in to the Finder to access it in the Finder contextual menu:

Code:
global parentFolder

set selUnixPaths to {}
set tempDir to quoted form of POSIX path of (path to temporary items folder as text)
set itemsUnixPaths to ""

tell application "Finder"
	set finderSelection to selection
	set parentFolder to (container of (item 1 of finderSelection as alias))
	if (length of finderSelection) > 1 then
		repeat with selectedItem in finderSelection
			copy quoted form of ("./" & (name of (selectedItem as alias))) to end of selUnixPaths
		end repeat
		repeat with selectedItem in selUnixPaths
			if itemsUnixPaths = "" then
				set itemsUnixPaths to selectedItem
			else
				set itemsUnixPaths to itemsUnixPaths & " " & selectedItem
			end if
		end repeat
		set archivename to my checkName("Archive.zip")
	else
		set itemsUnixPaths to quoted form of ("./" & name of (item 1 of finderSelection as alias))
		set namewitoutext to my trimext((item 1 of finderSelection) as alias)
		set archivename to my checkName(namewitoutext & ".zip")
	end if
end tell

set shellScript to "cd " & quoted form of (POSIX path of (parentFolder as alias)) & "; zip -b " & tempDir & " -9r '" & archivename & "' " & itemsUnixPaths & " -x *.DS_Store"

with timeout of 60 * 60 seconds
	do shell script shellScript
end timeout

on trimext(myfile)
	tell application "Finder"
		set fileextlenght to count of ((name extension of (myfile)) as text)
		set fileName to name of (myfile)
	end tell
	if fileextlenght > 0 then
		return (items 1 thru -(fileextlenght + 2) of fileName) as string
	else
		return fileName
	end if
end trimext

on checkName(archiveFile)
	tell application "Finder"
		if exists file (((parentFolder as alias) as string) & archiveFile) then
			set fileName to (items 1 thru -5 of archiveFile)
			set x to 2
			repeat while exists file (((parentFolder as alias) as string) & archiveFile)
				set archiveFile to fileName & " " & x & ".zip"
				set x to x + 1
			end repeat
		end if
		return archiveFile
	end tell
end checkName

Edit: You're welcome. I had to figure this out recently so it's great that you asked.
 
wow. that Automater script looks like a complete mess! it must have taken a long time. Automater has always been a mystery to me, and I am a programmer, so thats saying something. thanks so much for sharing this!
 
wow. that Automater script looks like a complete mess! it must have taken a long time. Automater has always been a mystery to me, and I am a programmer, so thats saying something. thanks so much for sharing this!

Hah. Sorry. I did not write the script but, it took some digging around to find it. And again, you're welcome.
 
Why take sixty lines to do one simple command?

Code:
find ~ -name \.DS_Store -print0 | xargs -0 rm
 
I use the Terminal...

Code:
cd [directory]
zip -r [filename].zip *

Where directory is the directory you want to zip and filename is what you want the zip to be called. This will create the zip file inside of that folder that you just zipped.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.