Creating ZIP in JSX on macOS

Community Expert ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

Hey everybody.

 

This is a JSX question that runs on Illustrator. But I'm not sure if it can be called scripting in Illustrator.

 

I want to create a ZIP of a specified directory in JSX on macOS.
I knew that, but I couldn't do it.
As a compromise, I created a ".command" file with terminal commands. But the permissions were not acceptable.

 

I compromised further and created a .command file with invisible attributes in advance, so that JSX could only rewrite the contents of the .command file.
The rewriting succeeded. However, the contents of the .command file were not executed.

 

I checked before and after the rewriting with a text editor, and found that the line feed code was identified as CR after the rewriting in JSX.
I changed it to LF in the editor and double-clicked the saved file.
But I don't understand, the rewritten text in JSX also has (10) as the character code for newlines.

I don't know much about this area.I tried all the File.linefeed properties, but it didn't help.

 

So, I'm looking for a solution to my problem, or an alternative way to create a ZIP file in JSX on macOS.
BridgeTalk preferably not used.

 

Thank you in advance!

TOPICS
Scripting

Views

79

Likes

Translate

Translate

Report

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 ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

Hi @ajabon grinsmith,

I use the exact same flow for one of my projects and no one has complained so far about the zip not working or the command file execution failing. I use "Unix" as linefeed, and as you discovered the command file is created already with proper permissions and within the script I open and rewrite the script conents and then execute it. See the relevant code snippet from my codebase, probably you might find something from your code.

 

var helperFile = new File("<Path to command file>/test.command")
helperFile.open("w")
helperFile.lineFeed = "Unix"
helperFile.writeln("#!/bin/sh")
helperFile.writeln("cd " +  tempFolder.parent)
helperFile.writeln("zip -r " + des.name + ".zip " + des.name)
helperFile.writeln("rm -r " + des.name)
helperFile.close()
helperFile.execute()

 

-Manan

Likes

Translate

Translate

Report

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 ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

Manan Joshi,

Thanks for the useful information.
My code was distinctly different from the one you presented because the code to be written was 

"#!/bin/sh\nsomething\nsomething" 

I immediately copied your method and modified it ....
However, I could not improve it.
I tried opening the file in two different editors, both with CR...
The upper one is before and the lower one is after.

スクリーンショット 2022-09-05 20.27.58.png
My OS environment is Mojave (10.14.6).

Likes

Translate

Translate

Report

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
Participant ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

Did you give execute permissions to the invisible .command file?

 

Example:

chmod +x ~/Desktop/.compressZip.command



Likes

Translate

Translate

Report

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 ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

sttk3,

Thank you for your help every time.
As for changing permissions, I have adopted a compromise solution to rewrite the contents in an invisible file saved with -rwxr--r-- in advance, as I believe there is no way to do this in Illustrator's JSX.
Or is there a way to change permissions from JSX in Illustrator?

Likes

Translate

Translate

Report

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 ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

Hi @ajabon grinsmith,

I retested on my MAC which incidentally is also 10.14.6 and it works. So here is what I did

  • I created a test.command file. Gave it 777 permission
  • Used the following code

 

var helperFile = new File("/Users/manan/Downloads/Test/abc/test.command")
helperFile.open("w")
helperFile.lineFeed = "Unix"
helperFile.writeln("#!/bin/sh")
helperFile.writeln("cd /Users/manan/Downloads/Test/abc" )
helperFile.writeln("zip -r out.zip def")
helperFile.close()
helperFile.execute()

 

I hardcoded the paths to be sure that nothing else is interfering.

I am sharing a screenshot of how my command file looks with regards to linefeed when I open it in VSCode.

Screenshot 2022-09-05 at 5.32.05 PM.png

One thing I noticed however. Since the last time I tried this code I had migrated from bash shell to zsh as my default shell in terminal. With this setup the execution of the command file from estk failed. However, on switching back to bash as the dedualt things started working. Probably another test could be to change the shell direction at the top of the command file

P.S.:- It does not seem to work so far with zsh so if you have that setup change to default bash on the terminal and test

-Manan

Likes

Translate

Translate

Report

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
Participant ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

Worked fine with ajabon grinsmith and Manan Joshi's code. 

  • macOS 10.14.6/11.6.8
  • Illustrator 25.4.7/26.5.0

Sorry, I could not find out why it does not work, or why the line break code changes, etc.

 

It is safer to not allow change permissions from JSX. I recommend that you proceed based on the current invisible command plan.

Likes

Translate

Translate

Report

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 ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

LATEST

sttk3,

I think your opinion reinforces the inevitability of my chosen means.

Very reassuring. Thank you!

Likes

Translate

Translate

Report

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 ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

Manan, 

 

I stared at the two codes, my own and yours, for eight hours and compared them.
I found a mistake in the syntax of my code. > line "f "eed...

 

And it worked.
Thank you very much, very much.

 

And I tested it by switching to the default shell you advocate, and it worked fine with zsh.
A bit risky if that's true, since this project is used by an unspecified user.
I'll continue testing with Monterey later.

 

Thanks again!

 

Likes

Translate

Translate

Report

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

Save time with Adobe Express quick actions