Zip (compress) Packaged InDesign File at end of process

Hello, I’m very new to AppleScript.

I’ve created a droplet that creates various PDF versions and packages an InDesign file. Searching this forum has proved very helpful).

I’d like to zip the folder created at the end of the process and delete the folder, leaving only the zip archive.

I believe this necessitates using shell script, and have seen several examples of how to do this, but I can’t for the life of me get the shell script to recognise the path of the package folder.

Here is the tail end of the script from exporting the package onwards:

tell application id "com.adobe.InDesign"

set mgPackageFilePath to grandparentFolderPath & “To Supply/” & mgShortName as string
tell active document
package to mgPackageFilePath with ignore preflight errors, copying profiles, including hidden layers, copying linked graphics and include pdf without copying fonts, creating report and updating graphics
end tell
close active document saving no
end tell

This works fine, and created the following folder “Volumes/Wakefield Studio/HH Global/Studio/Script_Test/E02167857_TEST/PASSIONA5_538/To Supply/E02167857_PASSIONA5_538_0416” with the example file I’m using.

Now I believe I can use the string mgPackageFilePath to serve up to the shell script “zip” command, but every iteration I’ve tried gives errors.

I can plug this in and it works perfectly (because I’ve just inputted the actual path of the test file I’m using):

tell application "Finder"
	set theItem to alias ":Volumes:Wakefield Studio:HH Global:Studio:Script_Test:E02167857_TEST:PASSIONA5_538:To Supply:E02167857_PASSIONA5_538_0416"
	set itemPath to quoted form of POSIX path of theItem
	set fileName to name of theItem
	set theFolder to POSIX path of (container of theItem as alias)
	set zipFile to quoted form of (theFolder & fileName & ".zip")
	do shell script "zip -rj " & zipFile & " " & itemPath
end tell

but obviously I want to be able to replace the given path with the output of the package function above.

Please help!

Thanks, Kalvin

Here is a handler which I use for years.


on zipIt(fichier) (* fichier is an HFS path*)
	local Nom, ext, dossier, isPackage, nomAvecDateHeure, source, dest
	set fichier to "" & fichier
	tell application "System Events" to tell disk item fichier
		set Nom to name
		set ext to name extension
		set dossier to path of container
		set isPackage to package folder
	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
	if isPackage then
		set dest to quoted form of POSIX path of (dossier & nomAvecDateHeure & ".zip")
		do shell script "ditto -ck " & source & " " & dest
		set dest to quoted form of POSIX path of (dossier & nomAvecDateHeure)
		do shell script "cp " & source & " " & dest
	end if
end zipIt


Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) jeudi 21 avril 2016 12:04:19

Thank you very much for the quick reply!

I may need a little help integrating this into my own script, I’m not entirely sure what everything is doing there?


To call the handler, your script must contain an instruction resembling to :

my zipIt(HFS path to the package to compress)

Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) jeudi 21 avril 2016 13:49:06

Got it!

Thank you very much, this is working perfectly now! Was the last little piece of the puzzle and was driving me mad.

Cheers! k

Hi, Kalvin. In your original post, the one thing that had to be changed was the hard-coded alias path. Since only Name and Container need to be inside the Finder block, I made a couple additional stylistic adjustments.

	set theItem to (run script "choose " & (choose from list {"file", "folder"})) --tune to file or folder
	set itemPath to theItem's POSIX path's quoted form
	tell application "Finder" to set {fileName, theFolder} to {theItem's name, (theItem's container as text)'s POSIX path}
	do shell script "zip -rj " & (theFolder & fileName & ".zip")'s quoted form & space & itemPath