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);
Related
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
I'm currently working on a react/electron app and I want to be able to copy a file that's outside the app (could be any file type) using ctrl+c or right click copy.
How can I retrieve that file's name and path inside my app? I've tried navigator.clipboard.readText() and .read() and haven't had any luck.
Unfortunately in Electron, clipboard is still highly platform-dependant requiring different code depending on which platform you're running. Here's a snippet for a single file to get you started. If you need access to multiple files, see this snippet.
const { clipboard } = require('electron')
let text = null
if(process.platform === 'darwin') { // MacOS
text = clipboard.read('public.file-url')
} else { // Windows
text = clipboard.readBuffer('FileNameW').toString('ucs2')
} // TODO: Linux
console.log(text);
Depending on your presentation, you may need to convert to a human readable format (e.g. file:/// vs. C:\, etc)
I have some javascript code that allows users to drag and drop files in IE.
The problem I have is that they would like the file deleted after being dragged, but I can't seem to get the file path, just the name.
I have seen many references to e.dataTransfer.files[0].path, but it always comes back as 'undefined' when I try it.
Any ideas why e.dataTransfer.files[0].path does not work, or how I can get the file path?
$(document).ready(function (ex) {
var holder = document.getElementById('holder');
holder.ondragover = function () { this.className = 'hover'; return false; };
holder.ondrop = function (e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
var path = e.dataTransfer.files[0].path;
fileArray.push(file);
//alert(e.target.id);
var reader = new FileReader();
reader.readAsDataURL(file);
};
});
that's not possible for a web app, but if your users would run an app on their machine, you could build an electron app. inside electron you get the e.dataTransfer.files[0].path property, which you can then use to delete the file.
https://www.electronjs.org/
The file doesn't have property path.
You can experiment with it here and the complete list of file properties can be found here.
To read the file one uses FileReader as you did, without using the path explicitly.
After trying everything I could find, I am of the opinion that it is not possible.
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.
I am trying to make a small scraper with node (electron) for learning purposes. I am stuck at trying to download files from the webpage.
For now I do :
fetch(fileUrl).then(function(response){
return response.arrayBuffer();
}).then(function(buffer){
var buff = new Int32Array(buffer);
fsp.writeFile("filename.pdf",buff).then(function(){console.log('Success!')})
})
But the fs part is wrong - I just can't figure out how to make it right. How do I know what sort of data (uint8, int32, etc.) I should use? I'm really confused about how this should work.
Assuming you're running Electron v0.37.5 or later, I think this should do the trick:
fetch(fileUrl).then(response => {
var buff = Buffer.from(response.arrayBuffer());
fsp.writeFile("filename.pdf", buff).then(() => {
console.log('Success!')
});
});