Copy link to clipboard
Copied
Hello -
I made a very long Adobe Javascript that does a lot of things (that work).
Part of that script is the request to compress a folder on the desktop (of my MacBook) to .ZIP.
It's this last part that doesn't work. I've tried several things but nothing seems to work.
So my question is, is it possible to compress a .ZIP folder via a script in Illustrator?
If so, could someone share with me the few lines of programming needed to do it correctly?
Thanks a lot.
- Dimitri
Okay, I have included the code for your JSX script and the AppleScript application you need to also have. To make things simple, everything is setup to work from the desktop but you can edit the paths to whatever works best for your situation. Please note, the AppleScript must be saved as an app, so when you go to save make sure you choose "Application" in the file format dropdown menu. You should also run the AppleScript app manually first by double-clicking it to ensure you allow it the necess
...Copy link to clipboard
Copied
There is no good way unfortunately but it can be done. Here are a few options (for Mac)... Let me know if you need help implementing any of them? Cheers!
Option A:
Option B:
Option C:
Copy link to clipboard
Copied
Hi jduncan -
Thx for your reply.
Yes, I'd like some help with may be the first option.
It's in the "applescript with `File.execute()`" where I'm stuck. At first I though I could do it. But I only get errors messages.
On the fly "Folder path" should/could be assigned in a variable inside the Illustrator Javascript.
Thx already…
Enjoy your day.
- Dimitri
Copy link to clipboard
Copied
Okay, I have included the code for your JSX script and the AppleScript application you need to also have. To make things simple, everything is setup to work from the desktop but you can edit the paths to whatever works best for your situation. Please note, the AppleScript must be saved as an app, so when you go to save make sure you choose "Application" in the file format dropdown menu. You should also run the AppleScript app manually first by double-clicking it to ensure you allow it the necessary permission to run correctly.
Try this out and let me know if you have any questions?
ZipFolder.jsx
(function () {
// set path of text file with folder path
var file = new File(Folder.desktop + "/" + "folder_path.txt");
// set path to bash script
var script = new File(Folder.desktop + "/" + "ZipPath.app");
// choose a folder to zip (could be hardcoded or relative to current doc without dialog)
var folder = Folder.selectDialog("Choose a folder to zip.");
// no need to continue if the user doesn't select a folder
if (!folder) {
return;
}
// write folder path to the text file
try {
file.encoding = "UTF-8";
file.open("w");
file.write(folder.fsName);
// run the bash script
var result = script.execute();
if (!result) {
alert("Oops! Something went wrong with the bash script.");
}
} catch (e) {
alert("Error writing file " + file + "!\n\n" + e);
return false;
} finally {
f.close();
}
})();
ZipFolder.app
-- ZipFolder.app
-- Notes:
-- * must be saved as an AppleScript application
-- * make sure to run the AppleScript first by double-clicking it to enable proper system permissions
-- Path to the text file containing the folder path
set pathToTextFile to "/Users/jbd/Desktop/folder_path.txt"
-- Read the first line from the file as the folder path
set folderPath to paragraph 1 of (read (POSIX file pathToTextFile) as «class utf8»)
-- Break folder path into parent and name
set AppleScript's text item delimiters to "/"
set pathParts to text items of folderPath
set folderName to item -1 of pathParts
set parentPath to "/" & (text items 1 thru -2 of folderPath as string) & "/"
-- Construct zip path
set zipFile to parentPath & folderName & ".zip"
set quotedZipFile to quoted form of zipFile
set quotedFolderName to quoted form of folderName
set quotedParentPath to quoted form of parentPath
-- Remove old zip file if it exists
do shell script "rm -f " & quotedZipFile
-- Zip the folder
do shell script "cd " & quotedParentPath & " && zip -r " & quotedZipFile & " " & quotedFolderName
-- Notify user
display dialog "Compression complete: " & folderName buttons {"OK"} default button 1
Find more inspiration, events, and resources on the new Adobe Community
Explore Now