create zip file without .ds_store files??

Discussion in 'macOS' started by Oats, Mar 16, 2007.

  1. Oats macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #1
    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?
     
  2. TheSpaz macrumors 604

    TheSpaz

    Joined:
    Jun 20, 2005
    #2
    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.
     
  3. Oats thread starter macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #3
    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!
     
  4. TheSpaz macrumors 604

    TheSpaz

    Joined:
    Jun 20, 2005
    #4
    Hah. Sorry. I did not write the script but, it took some digging around to find it. And again, you're welcome.
     
  5. indiekiduk macrumors 6502

    Joined:
    Jul 26, 2005
    Location:
    Glasgow, Scotland
    #5
    You can also use Stuffit in the contextual menu to archive to .zip, and in the settings you can choose to ignore finder files.
     
  6. pjrobertson macrumors 6502a

    Joined:
    Nov 14, 2007
    #6
  7. SC68Cal macrumors 68000

    Joined:
    Feb 23, 2006
    #7
    Why take sixty lines to do one simple command?

    Code:
    find ~ -name \.DS_Store -print0 | xargs -0 rm
    
     
  8. mnkeybsness macrumors 68030

    mnkeybsness

    Joined:
    Jun 25, 2001
    Location:
    Moneyapolis, Minnesota
    #8
    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.
     

Share This Page