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!
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()
Thanks for the useful information.
My code was distinctly different from the one you presented because the code to be written was
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).
Did you give execute permissions to the invisible .command file?
chmod +x ~/Desktop/.compressZip.command
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?
I retested on my MAC which incidentally is also 10.14.6 and it works. So here is what I did
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
Worked fine with ajabon grinsmith and Manan Joshi's code.
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.
I think your opinion reinforces the inevitability of my chosen means.
Very reassuring. Thank you!
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.