Help - Search - Members - Calendar
Full Version: How to compress folders with AppleScript?
InsanelyMac Forum > Apple World > Mac Programming and Development > AppleScript and Automator
Jonathan8
Hi everyone,

I am new to AppleScript and have recently created a back-up script, based on a tutorial written in the book "AppleScript: The Missing Manual". I've also read and did all the excercises present in "AppleScript for Absolute Starters", which means I have some basic understanding.

What I would like to do is to compress the backed-up folder (preferably by automatically making a .zip archive and then a dialog w
ndow where I 
wish to save the .zip file)

I've searched some other forums (including this one), but I can't get it to work.

Here is the relevant bit of my code:

CODE

(...)
set tempVar2 to display dialog "Would you like to compress your Opera preferences folder (using zip)?
This file could be opened on almost any Mac or PC." buttons {"No", "Compress"} default button 1
set theButtonPressed to button returned of tempVar2
if theButtonPressed is "Compress" then
do shell script ¬
("/usr/bin/ditto -c -k -rsrc --keepParent " & ¬
selectedFile & " " & (choose folder))
else
(...)


Any suggestion is welcome, even another type of compression (although a compression method that could be opened on many computers is preferred).

Thank you very much in advance.
A Nonny Moose
it would be easier to create an Automator workflow and then save it as a plugin for the Finder.

Or just use the Finder's "create archive" command in the menu.
PascalW
QUOTE(Jonathan8 @ Feb 4 2007, 04:37 PM) *
Hi everyone,

I am new to AppleScript and have recently created a back-up script, based on a tutorial written in the book "AppleScript: The Missing Manual". I've also read and did all the excercises present in "AppleScript for Absolute Starters", which means I have some basic understanding.

What I would like to do is to compress the backed-up folder (preferably by automatically making a .zip archive and then a dialog w
ndow where I 
wish to save the .zip file)

I've searched some other forums (including this one), but I can't get it to work.

Here is the relevant bit of my code:

CODE

(...)
set tempVar2 to display dialog "Would you like to compress your Opera preferences folder (using zip)?
This file could be opened on almost any Mac or PC." buttons {"No", "Compress"} default button 1
set theButtonPressed to button returned of tempVar2
if theButtonPressed is "Compress" then
do shell script ¬
("/usr/bin/ditto -c -k -rsrc --keepParent " & ¬
selectedFile & " " & (choose folder))
else
(...)


Any suggestion is welcome, even another type of compression (although a compression method that could be opened on many computers is preferred).

Thank you very much in advance.


You could use this:

CODE
do shell script "zip -r -j "& ZipFolder&" "& ToBeZippedFolder &""


where ZipFolder coud be something like

CODE
set zipfolder to (POSIX path of (choose folder with prompt "Where do you want to store the zip file?") & "nameofyourzipfile.zip")


and ToBeZippedFolder

CODE
set ToBeZippedFolder to (POSIX path of (choose folder with prompt "Choose the folder you want to zip"))
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.