I'm a graphic designer and a beginner at coding. So please dumb down for me :)
I have a script that I run through Illustrator. It embeds an image and removes a clipping mask on the file. I need this script to run on multiple .ai files in a folder.
The thing is, I cannot create a batch action (in Illustrator) to run the script. Our IT guy doesn't want to add the script to our Illustrator settings on multiple accounts. Is there a way to add code to my script to do this?
I need it to open all the files, run the script and save. The files can be left open on Illustrator, no need to close.
What code do I need to add to my script?
I am on a Mac not PC.
It can be done this way:
function my_script() {
// copy a full text of your script here
// or include the jsx file this way:
# include '~/Desktop/script/my_script.jsx'
}
function main() {
var folder = Folder.selectDialog('Please, select the folder');
if (!(folder instanceof Folder)) return;
var files = folder.getFiles('*.ai');
if (files.length == 0) {
alert('Folder doesn\'t content AI files');
return;
}
var i = files.length;
while (i--) {
var doc = app.open(files[i]);
my_script(); // <------- here your script is running
doc.save();
doc.close();
}
alert(files.length + ' files were processed');
}
main();
If you have subfolders with .ai files inside your chosen folder and you need to access them in the script, you may find this JS snippet useful as well:
https://gist.github.com/joonaspaakko/df2f9e31bdb365a6e5df
Related
im currently developping a script with extends script which is a javascript-similar script language, that we use to automate tasks in Adobe's Softwares (here its premiere pro)
Here is what my code is doing :
-i import files from a folder in my computer
-then i put them in a bin in my prpro project
-and for each of this file i create a bin with the file and a sequence
My problem is that the last file is not move in a bin
here is my code
root = app.project.rootItem
newFilesPath = "C:/Path"
newFilesBin = root.children[0]
app.project.importFiles(newFilesPath, true, newFilesBin, false)
app.project.save()
newFilesBin = root.children[0]
for(i=0; i<newFilesBin.children.numItems; i++){
newFile = newFilesBin.children[0]
name = newFile.name
newBin = root.createBin(name)
file.moveBin(newBin)
}
So if i put several file in the path it doesnt move the last file instead of moving every files
Thanks for help
I found the solution :
i just change the parameters of my for loop
for(i=-1; i<newFilesBin.children.numItems+1; i++)
I dont exatly know why its working but it works
I have a personal website written in AngularJS and NodeJS, and in the tech projects section I would like to embed README.md from a project on GitHub my account (the same way github.com) does it. I don't think iframe<> works for md files. So I have tried converting to HTML and PDF.
The second part of the README.md I want looks like this:
In particular, I would like to import the README.md files into my HTML. I have found two ways to do it:
Download the file, and convert to HTML.
var md_to_html = function(src, dest) {
// Get the markdown
var md = fs.readFileSync(src, "utf8");
var converter = new Remarkable();
var html = converter.render(md);
fs.writeFile(dest, html, function(err) {
if (err) {
return console.log(err);
}
console.log(dest + " was saved!");
});
}
Or Download the file, and convert to PDF.
var md_to_pdf = function(src, dest) {
fs.createReadStream(src)
.pipe(markdownpdf())
.pipe(fs.createWriteStream(dest));
}
Both work, however the photo disappears. That is because the dependencies let's say doc/img/photo.jpg does not get downloaded with the README. I have also written scripts to download the dependencies. But neither insert the photo into the README.pdf or README.html.
Has anyone done something like this? Embedded markdown in HTML with photos, or converted them to PDF or HTML with photos? If I could just import it kind of like a PDF with iframe<> that would be ideal, but if not, I will program it myself. But how?
So I have a personal website, and I have a button that I want to use to open photoshop and run a script for me. How do I do this?
It is not possible. It would pose a huge security risk to allow javascript to open programs on client side.
This has been up for awhile, but if the solution to this in node is to use a child_process.
you can npm install child_process
and the code to run executables would be to do
const exec = require("child-process").execFile;
var process = exec("Photoshop.exe", [*add options here*], {cwd:"C:/*path to photoshop*"});
you can do a lot of cool things afterwards like event handlers
process.on("close", code => {
console.log("process closed with code: "+ code)
})
process.on("exit", code => {
console.log("process exited with code: "+ code)
})
process.stdout.on("data", data => {
console.log(data)
})
You can read the Docs here: https://nodejs.org/api/child_process.html
maybe this
Code will open image in photoshop with the help of javascript. You just need to place your image file into photoshop->sample folder nothing more than that and you done with it.
var fileRef = new File(app.path.toString() + “/Samples/test.jpg”); // ‘samples’ is a folder resides in Program Files\Adobe\Adobe Photoshop CS5\samples
//open (fileRef);
var doc = open(fileRef);
// get document name (and remove file extension)
var name = tempName[0];
// convert to RGB; convert to 8-bpc; merge visible
doc.changeMode(ChangeMode.RGB);
doc.bitsPerChannel = BitsPerChannelType.EIGHT;
doc.artLayers.add();
doc.mergeVisibleLayers();
// rename layer; duplicate to new document
var layer = doc.activeLayer;
layer.name = tempName[0];
layer.duplicate(newDoc, ElementPlacement.PLACEATBEGINNING);
// close imported document
doc.close(SaveOptions.DONOTSAVECHANGES);
I have to crop all open psd files and save as jpg.
To speed up the workflow I am using a photoshop script that allows me to save the files one by one with specific jpg options.
I would like to enhanced the script by including a save all open files feature.
What would be the simples way to add this functionality to the script using javascript?
This is the structure of the script
//flatten image
//declare variable myJPEGOptions
//input jpg options
//save jpg to folder path
//close the document
The easiest way is to use Automate. You don't need to included anything special.
Write your script as you would normally with the intention of processing just one file.(which will flatten, process save and then close the document) as normal.
Then access your script in batch mode (File > Automate > Batch)
Select the your script and a folder with all your documents in.
Or if you want to modify your script you can:
// get all the files to process
var inFolder = Folder.selectDialog("Please select folder to process");
if (inFolder != null)
{
var fileList = inFolder.getFiles();
}
// and then loop over the file list
for (var i = 0; i < fileList.length; i++)
{
var doc = open(fileList[i]);
// process files here
// close files here
}
Just bare in mind that Photoshop will try to open any file in that list including things that it can't like text files or thumbnails thumbs.db :)
I'm not particularly using Flex but I am using javascript and html and css in a adobe air application. I would like to be able to unzip and zip files. I've looked at a few libraries but none worked as I needed it to. I read somewhere that I could use Fzip library but I need to do this in javascript most preferably but the files are actionscript files. Any advice? Thanks.
You can use almost any actionscript library with html/javascript air app. Example:
Download swc file for airxzip: http://code.google.com/p/airxzip/downloads/list
Rename swc to zip and unzip it
Rename included library.swf to coltware_airxzip.swf
Include the library on your page like this:
<script src="coltware_airxzip.swf" type="application/x-shockwave-flash"></script>
This reads a zip file and writes contents to output folder on the desktop (given you have included jQuery and the AIRAliases.js file from the SDK):
var input = new air.File();
input.addEventListener(air.Event.SELECT, function(event) {
var outputDirectory = air.File.desktopDirectory.resolvePath('output');
var reader = new window.runtime.com.coltware.airxzip.ZipFileReader();
reader.open(event.currentTarget);
$.each(reader.getEntries(), function(i, entry) {
if (!entry.isDirectory()) {
var stream = new air.FileStream();
stream.open(outputDirectory.resolvePath(entry.getFilename()), air.FileMode.WRITE);
stream.writeBytes(reader.unzip(entry));
stream.close();
}
});
});
input.browseForOpen('Select a zip file...', [new air.FileFilter('Zip files', '*.zip')]);
I wrote a sample app for Adobe Air + FZip using javascript.
Figured I'd share that here in case anyone else arrives here via Google.
Can never have too many working examples right?
Example -> http://www.drybydesign.com/?p=233