Jump to content

How to compress folders with AppleScript?


Jonathan8
 Share

3 posts in this topic

Recommended Posts

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:

 

(...)
		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.

Edited by Jonathan8
Link to comment
Share on other sites

  • 2 months later...
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:

 

(...)
		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:

 

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

 

where ZipFolder coud be something like

 

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

 

and ToBeZippedFolder

 

set ToBeZippedFolder to (POSIX path of (choose folder with prompt "Choose the folder you want to zip"))

Link to comment
Share on other sites

 Share

×
×
  • Create New...