How to enable execute privileges on a file on OSX
Copy link to clipboard
Copied
Hello!
I'm creating a .command file from my illustrator extend script to interact with the terminal. But when I try to do file.execute() it's telling me that it can't be executed since I don't have the appropriate access privileges.
This can be fixed manually if edit the file and do something like chmod u+x 777 on the .command file, but for this script it needs to create and delete the command file when necessary.
This is how I create the file
function writeFile(fileObj, fileContent) {
encoding = "utf-8";
fileObj = (fileObj instanceof File) ? fileObj : new File(fileObj);
fileObj.encoding = encoding;
fileObj.open("w");
fileObj.write(fileContent);
fileObj.close();
return fileObj;
}
Maybe there is some encoding that can be done? Any ideas?
Explore related tutorials & articles
Copy link to clipboard
Copied
What I did for one of my projects is create a .command file manually and give it execute access using the chmod command. Then in the script I used this base .command file, opened it wrote the new commands saved it, and then executed it. Hope that works for you as well
-Manan
Copy link to clipboard
Copied
Hello Manan,
This could be a potential solution. Currently my script creates and destroys this .command file during runtime and it works fine on windows. I'd have to refactor some code but it could work.
I am still curious if there is a way to set the permissions of the file at creation though, but thanks for the answer.
Copy link to clipboard
Copied
I was not able to find any other way. One possible approach could be to create the file, use Applescript to change its permission(I think we can launch AS from within JS). I would be interested to know what you finally come up with.
-Manan

