photoshop save all open jpegs script - javascript

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 :)

Related

Running a script on all .ai files in a directory

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

Get the Image URLs from Top.Images object

I'm working with a website that generates lots of images that I want to save to disk. To do so I need to get a list of URLs containing all the images.
The above picture was taking from the Application tab of Google Chrome's debugging tools. Each of the 'green' files is a 'stored image' or rather, a referenced image URL.
How can I access this list from JavaScript console?
If it is not possible to access this folder/object from javascript, would it be possible to:
Query some database on disk that might contain the files.
Access the files via the Internet Explorer ActiveX Object?
var resources = window.performance.getEntriesByType("resource");
resources.forEach(function (resource) {
console.log(resource.name);
});
The above will list all of the files specified.
var resources = window.performance.getEntriesByType("resource");
resources.forEach(function (resource) {
if (resource.name.indexOf(".png") > -1 || resource.name.indexOf(".jpg")> -1)
console.log(resource.name);
});
As #Sancarn said with my extras line this function will writes all the images that have .png or .jpg as an extension. try it and let me know.

Illustrator JS Script Run without app.activeDocument

I have been using Illustrators API to create a script that is able to export .ai files swatches into a JSON format.
This however is all by having to open the Illustrator file and click
File > Scripts > Run My Script.
This is something that is very tedious and was wondering if there was a way in order to take the the files location (file path) and just execute the program using something like Node which will just use my already existing code and my AI file.
Currently I have something that looks along the lines of:
var Exporter = function() {
this.swatchGroup = 'ClientColours';
this.myApp = app.activeDocument;
this.chosenSwatchGroup();
this.writeFile(); };
What I am thinking is there not a way to instead of having this.myApp = app.activeDocument; to rather have something like this.myApp = Path(../my location);?
I have been making us of this documentation Jongware and Adobe Documentation just cant seem to find the answer I am looking for in order to get closer to this sort of automation.
EDIT
Did some digging and found the application documentation and there is a 'path' property just not sure on its implementation. Documentation
Yes, you can do this by providing path. But you have to open that file and that file will be your activeDocument. For eg :
var file = File("../your location");
app.open(file);
this.myApp = app.activeDocument;
By this, the file at your location will get open in Illustrator and will be activeDocument.

Path to select all images from a folder in the disk using javascript

I am loading all images from a folder from local disk and displaying using javascript.
I have given a button to open a local disk and choose files.
But I want to dynamically load images from a particular path on DOMready/onload instead of loading though a file select.
Here is link to what I have tried: http://fiddle.jshell.net/rrYxn/
Please please help.
It is not possible to load file arbitrary from any users local disk.
if possible , when you open Facebook.. it can upload all the photos in you computer with out asking you ans post it :). so simply no.
what you may need is to load some file from server (not local drive/path).
you can define th files to want to load like
var files = [
'http://localhost/myproject/image1.png',
'http://localhost/myproject/image2.png',
'http://localhost/myproject/image3.png'
]
later the localhost will change to the domain name.
and use some script function to load these images
function loadImages(){
for(var i=0; i< files .length; i++) {
var img = new Image();
img.src = files[i];
document.getElementById('wrapper').appendChild(img);
}
}

HTML/Javascript: Getting a List of all files and subdirectories in a given directory

I am working on an interface that allows the to access the file system on the client side. The user should be able to browse through the file system, select a directory and my system will display list of files and sub-directories of the selected directory.
I have tried using HTML5 File API, but that apparently only allows users to select files (not folders).
Any pointers/help in this direction will be appreciated.
This cannot be done in JavaScript as it would be a potential security issue. Only files selected by the user via a file dialog can be accessed using JavaScript.
Here's a pretty nice article on the File API if you haven't come across it yet.
If it's still an open issue, then let me give you a solution that might work for you.
HTML
File input for selecting a directory:
<input type="file" id="file-input" webkitdirectory="" directory=""/>
JavaScript
The following script collects all files from the given folder and from ALL sub folders.
Even from sub-subfolders, etc.
$("#file-input").on("change", function(e) {
var thefiles = e.target.files;
$.each(thefiles, function(i, item) {
var thefile = item;
var reader = new FileReader();
reader.onload = function() {
files.push(thefile);
};
reader.readAsArrayBuffer(thefile);
});
});

Categories