Skip to main content
ajabon grinsmith
Community Expert
Community Expert
September 5, 2022
Question

Creating ZIP in JSX on macOS

  • September 5, 2022
  • 2 replies
  • 699 views

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!

This topic has been closed for replies.

2 replies

Legend
September 5, 2022

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

 

Example:

chmod +x ~/Desktop/.compressZip.command



ajabon grinsmith
Community Expert
Community Expert
September 5, 2022

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?

Community Expert
September 5, 2022

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.

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

-Manan
Community Expert
September 5, 2022

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

-Manan
ajabon grinsmith
Community Expert
Community Expert
September 5, 2022

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.


My OS environment is Mojave (10.14.6).