Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Service to "Make Protected Zip" files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Service to "Make Protected Zip" files
Authored by: jelockwood on Nov 06, '13 08:26:53AM
I tried out the modified version posted by Chocky with the password hidden and it (mostly) works fine. I did however find a few issues.

1. It includes all the parent hierarchy in the zip file it produces, i.e. if your in /Users/youraccount/Downloads and select a file and make a zip it will contain not only your selection but the parent hierarchy of Users/youraccount/Downloads/ as well. This is because the version written by Chocky (and the original by ThomasMyers) include the -j flag in the command. (Probably related to the following two issues.)

Note: This is contrary to the behaviour of the built-in 'Compress' command provided by Apple in the Finder.

2. If you try to make a zip of a package type file the result when decompressed does not restore a working package.

3. If you try to make a zip of a normal folder it fails completely.

I have fixed all the above issues, the modified version is listed below. Tested only under Mountain Lion so far.


on run {input, parameters}
	set dialogResults to display dialog "Name for zipped file (no extension)" default answer "Archive" buttons {"OK", "Cancel"} default button "OK"
	if button returned of dialogResults is "OK" then
		set passwd to "x"
		set passwd_2 to "y"
		repeat while passwd ≠ passwd_2
			tell application "System Events"
				activate
				set passwd to text returned of (display dialog "password for zipped file" default answer "" buttons {"OK", "Cancel"} default button "OK" with hidden answer)
				set passwd_2 to text returned of (display dialog "Please reenter your password" default answer "" buttons {"OK", "Cancel"} default button "OK" with hidden answer)
			end tell
			
		end repeat
		set archiveName to text returned of dialogResults
		
		tell application "Finder"
			set archiveFileName to archiveName & ".zip"
			-- Append on a number if file exists.
			set suffix to 1
			set theFileExists to true
			repeat while theFileExists
				try
					set archiveFile to ((container of (item 1 of input) as Unicode text) & archiveFileName)
					if exists file archiveFile then
						set archiveFileName to archiveName & suffix & ".zip"
						set suffix to suffix + 1
					else
						set theFileExists to false
					end if
				end try
			end repeat
		end tell
		set itemStr to ""
		repeat with thisItem in input
			set itemPath to quoted form of (POSIX path of thisItem)
			tell application "Finder"
				set parentFolder to POSIX path of (container of thisItem as alias)
				set itemName to name of thisItem
				set itemStr to itemStr & quoted form of itemName & " "
			end tell
		end repeat
		if (the last character of itemStr is " ") then set itemStr to characters 1 thru ((length of itemStr) - 1) of itemStr as string
		set zipFile to POSIX path of (parentFolder & archiveFileName)
		set cmd to "cd " & parentFolder & " ; zip -P " & passwd & " -r " & zipFile & " " & itemStr & " -x *.DS_Store"
		do shell script cmd
	end if
	return
end run
Edited on Nov 06, '13 08:29:32AM by jelockwood


[ Reply to This | # ]