Zip a set of folders before copying

Hello!
I’m thinking about a script that would allow me to zip a set of files then copy the zipped file over to a server–like a compressed backup of sorts. I’m not sure how to go about it. Is this the way to start for the zipping?

tell application “Terminal”
activate
try
do script “zip /Users/corey/Desktop” in window 1
delay 15
end try
end tell

Also, is zip the best way to do this or wold gzip or tar or some such command be better?
Thanks!
Corey

Model: PB G4/867 MHz
Browser: Safari 412
Operating System: Mac OS X (10.4)

You can do shell script right in applescript. No need to go through terminal.

Whatever compression you use should return a stdout when it’s done. You can check that when it comes back – no need to delay.

Oh! What is the format for doing shell script in AS? Is this correct?

do shell script (“tar -cvf /backup.tar /Users/corey/Desktop’”)

What’s in parentheses is what I’d type on Terminal. Will this work in AS?

THANKS!
Corey

Browser: Firefox 1.0.4
Operating System: Mac OS X (10.4)

So in Terminal, I would type a path – especially a path that has folder names with spaces – like this:

/Users/corey/Library/“Application Support”/“Mail Downloads”

If I put the quotes in AS, Script Builder tells me it doesn’t like the " there. What would I use instead of " in the script?

I’ve tried putting \ in front of the " character, but I still get errors saying the path doesn’t exist. So the quotes are basically not getting across to the shell. How would I go about getting them in there?

THANKS!
Corey

Hi Corey,

Use quoted form of. Like:

set x to quoted form of "/Users/corey/Library/Application Support/Mail Downloads"

Returning to your original question. I use ditto to make zip files as I understand zip does not deal with resource forks well.

Best wishes

John M

This is a handler I use to make zip files of files or folder paths given to it.

-- File Zipper
-- Creates zipped file in same folder -- Pass file/folder path to this handler
on fileZipper(myFile)
	if (myFile as text) ends with ":" then
		set myDelimiters to AppleScript's text item delimiters
		set AppleScript's text item delimiters to {":"}
		set myFile to (text items 1 thru -2 of (myFile as text) as text)
		set AppleScript's text item delimiters to myDelimiters
	end if
	set zipFile to (myFile & ".zip") as text
	do shell script "/usr/bin/ditto -c -k -rsrc --keepParent " & (quoted form of (POSIX path of myFile)) & " " & (quoted form of (POSIX path of zipFile))
	return zipFile
end fileZipper

I got it going…on one hand it was an error on my part-trying to put in a file path that wasn’t actually there. On the other hand, when typing in these shell commands, quotes have to be thus:

do shell script (“tar /backup.tar /Users/corey/Library/"Application Support"/iCal”)

Note the backslash before the quotes…that makes the shell understand the quotes–and it helps if you make sure the path really exists. :stuck_out_tongue:

Here’s the script as i took it now:

do shell script (“tar /backup.tar /Users/corey/Desktop /Users/corey/Documents --all the paths to the other files I want separated by a space-”)
do shell script (“gzip /backup.tar”)

tell application “Finder”
duplicate file “Hard Drive:backup.tar.gz” to folder “server area”
end tell

do shell script (“rm /backup.tar.gz”)

And voilá I have a backup script!

Thanks for the help and suggestions all!
Corey