Zip Folder Finder syntax

Hi All,

Found great example on zipping folders, thanks StefanK. But when I use in my script I get an sytax error, maybe how I am passing the paths? Here is the code snippet from StefanK;

property deleteOriginal : false

on open theseFolders
	repeat with oneFolder in theseFolders
		if (folder of (info for oneFolder)) then
			tell (POSIX path of oneFolder) to set {theSource, theDestination} to {it, it's text 1 thru -2 & ".zip"}
			do shell script ("/usr/bin/ditto -c -k " & quoted form of theSource & " " & quoted form of theDestination)
			if deleteOriginal then do shell script "/bin/rm -r " & quoted form of theSource
		end if
	end repeat
end open

And here is the part of my code:

tell application "Finder"
	if (folder of (info for BatchFolder as alias)) then
		tell (POSIX path of BatchFolder) to set {theSource, theDestination} to {it, it's text 1 thru -2 & ".zip"}
		do shell script ("/usr/bin/ditto -c -k " & quoted form of theSource & " " & quoted form of theDestination)
	end if
end tell

Where BatchFolder is ““Macintosh HD:Users:robfleming:Desktop:DDA_AutoProcess:20100514:2010051407” as alias” or as string or neither.

The rest of the script works fine, just throws and error when trying to locate the file? Any help or pointers would be great, thanks.

Model: UB MBP 17inch
AppleScript: 2.1.2
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

try this - If i have understood the query properly

set BatchFolder to choose folder
tell application "Finder"
set theDestination to container of BatchFolder
	tell (POSIX path of BatchFolder) to set {theSource, theDestination} to {it, it's text 1 thru -2 & ".zip"}
	do shell script ("/usr/bin/ditto -c -k " & quoted form of theSource & " " & quoted form of theDestination)
end tell

Val

Thanks for your help delpucci, path to folder updates every time the process runs automatically so there is no user interaction, here is how I used your suggestion:

set BatchFolder to "Macintosh HD:Users:robfleming:Desktop:DDA_AutoProcess:20100514:2010051407" as alias
tell application "Finder"
	set theDestination to container of BatchFolder
	if (folder of (info for BatchFolder as alias)) then
		tell (POSIX path of BatchFolder) to set {theSource, theDestination} to {it, it's text 1 thru -2 & ".zip"}
		do shell script ("/usr/bin/ditto -c -k " & quoted form of theSource & " " & quoted form of theDestination)
	end if
end tell

and here is the error message that is generated;

Result:
error "Can't get folder of {name:\"2010051407\", creation date:date \"Friday, 14 May 2010 4:25:43 PM\", modification date:date \"Friday, 14 May 2010 5:17:23 PM\", size:227251, folder:true, alias:false, package folder:false, visible:true, extension hidden:false, name extension:missing value, displayed name:\"2010051407\", default application:alias \"Macintosh HD:System:Library:CoreServices:Finder.app:\", kind:\"Folder\", folder window:{0, 0, 0, 0}, file type:\"

I found this at macscripter.net but forgot to copy the url.

on run
	display dialog "Choose a file or folders?" buttons {"Cancel", "Folders", "File"} default button 3 with icon note
	
	if button returned of result is "File" then
		choose file with prompt "Create ZIP file of this file:" without invisibles
		get {result}
	else
		choose folder with prompt "Create ZIP files of these folders:" with multiple selections allowed
	end if
	
	open result
end run

on open droppedItems
	set ASTID to AppleScript's text item delimiters
	
	repeat with sourceFile in droppedItems
		set {sourceName, sourceExtension, sourceIsFolder} to {name, name extension, folder} of (info for sourceFile without size)
		
		set sourceFile to sourceFile as Unicode text
		set AppleScript's text item delimiters to {":"}
		
		if sourceIsFolder then
			set sourceParent to POSIX path of (text 1 thru text item -3 of sourceFile)
			set recursive to "r"
			
			get sourceName
		else
			set sourceParent to POSIX path of (text 1 thru text item -2 of sourceFile)
			set recursive to ""
		end if
		
		-- Remove extension from sourceName
		set AppleScript's text item delimiters to {"."}
		try
			get text 1 thru text item -2 of sourceName
		on error
			get sourceName
		end try
		
		do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8').lower().replace(' ','-').encode('utf8')\" " & quoted form of result
		
		if sourceExtension is in {"applescript", "scpt", "scptd", "app"} then
			get result & "_"
		else if sourceExtension is "dmg" then
			get result & ".dmg.zip"
		else
			get result & ".zip"
		end if
		
		-- Get path to zip file
		choose file name with prompt "Save zip file as:" default name (result)
		get result as Unicode text
		
		if (text -4 through -1 of result) is not ".zip" then
			set zipFile to POSIX path of result & ".zip"
		else
			set zipFile to POSIX path of result
		end if
		
		try
			do shell script "cd " & quoted form of sourceParent & "; /usr/bin/zip -qo9" & recursive & space & quoted form of zipFile & space & quoted form of sourceName
		on error errMsg number errNum
			set AppleScript's text item delimiters to ASTID
			display alert "Error while creating ZIP file. (" & errNum & ")" message errMsg buttons {"Cancel"} default button 1
			error number -128
		end try
	end repeat
	
	--    beep 2
	set AppleScript's text item delimiters to ASTID
end open

Tom

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

That is really handy, Tom.

Rob,

I don’t have the if statement

if (folder of (info for BatchFolder as alias)) then

end if

in my script.

just try it without that if statement.

Val