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: prr on Nov 07, '13 05:57:32PM

I'm having some trouble with this Service as it seems to not like file paths with spaces in them. Is that possible? That's what it seems like, but the "The action “Run AppleScript” encountered an error." error message is kind of vague, so it's hard to tell.

That all said, this works great otherwise! Thanks!



[ Reply to This | # ]
Service to "Make Protected Zip" files
Authored by: jelockwood on Nov 20, '13 09:21:15AM
per you were right. If one of the parent folders of the selected items has a space in the name it failed. I have (hopefully) fixed this in the version below.

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 quoted form of POSIX path of (parentFolder & archiveFileName)
		set cmd to "cd " & quoted form of parentFolder & " ; zip -P " & passwd & " -r " & zipFile & " " & itemStr & " -x *.DS_Store"
		do shell script cmd
	end if
	return
end run


[ Reply to This | # ]