Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

• Compress a folder on desktop via Adobe Javascript, possible?

Enthusiast ,
May 07, 2025 May 07, 2025

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

 

TOPICS
How-to , Scripting
261
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 07, 2025 May 07, 2025

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

...
Translate
Adobe
Community Expert ,
May 07, 2025 May 07, 2025

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:

  1. write the folder path to a file
  2. fire a pre-built applescript with `File.execute()`
  3. read the folder path inside of your applescript and the let applescript zip the folder for you

 

Option B:

  1. write the folder path to a file
  2. fire a pre-built executable bash script
  3. read the folder path inside of your bash and the let the `zip` utility zip the folder for you

 

Option C:

  1. use the clipboard trick from @CarlosCanto to copy the folder path to the clipboard in JSX
  2. fire a pre-built applescript with `File.execute()`
  3. read the clipboard (folder path) inside of your applescript and let applescript zip the folder for you

 

dad x 2. designer. maker. fun haver. ‍
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 07, 2025 May 07, 2025

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 07, 2025 May 07, 2025
LATEST

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

 

dad x 2. designer. maker. fun haver. ‍
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines