Zip then move original to the trash

Hi,

I create pdfs for clients, compress them to zip files and then email them. This means that I have an original larger pdf and then a zip file. I don’t need both so I would like to automatically delete the original file after compressing.

Any ideas?

Thanks,
Cindy in Indy

Hello

Here is a piece of code which I use very often.


set fichier to (path to desktop as text) & "activité copie.pdf"
tell application "System Events" to tell disk item fichier
	set Nom to name
	set ext to name extension
	set dossier to path of container
end tell

set source to quoted form of POSIX path of fichier
set nomAvecDateHeure to (text 1 thru -(2 + (count of ext)) of Nom) & (do shell script "date +_%Y%m%d-%H%M%S.") & ext

set dest to quoted form of POSIX path of (dossier & nomAvecDateHeure & ".zip")
do shell script "ditto -ck " & source & " " & dest
do shell script "rm " & source

Yvan KOENIG (VALLAURIS, France) lundi 24 septembre 2012 19:04:25

Here’s a very similar script I use to compress pdf files occasionally:


set tFile to (choose file of type {"PDF"}) as text

set source to quoted form of POSIX path of tFile
set dest to quoted form of POSIX path of (tFile & ".zip")

do shell script "ditto -ck " & source & space & dest
do shell script "rm " & source

Note that the PDF will not appear in the trash – rm simply removes it.

Hello

I’m accustomed to put a date-time stamp because very often I receive original files whose name was already used.
The stamp get rid of duplicates.

Yvan KOENIG (VALLAURIS, France) lundi 24 septembre 2012 20:22:06

Hello!

When you execute the line below, a preference pane for the built in archieve utility will be revealed, there are options there, to move the archieved files to trash after archieving.

There is also an option to set archieve format to zip there, which you must choose. :wink:

When you have set those options, then you won’t need a script at all, every file you choose to archieve the normal way, by rightclicking and choosing compress, will get its original moved to trash.


do shell script "open " & "/System/Library/CoreServices/Archive\\ Utility.app/Contents/Resources/Archives.prefPane/"