Hi, I'm wondering if anyone can help - I need to create a very simple script but I am already struggling - I need to save the active document in the current location, same filetype, with the existing filename, but with an addition e.g. 'C:\currentpath\currrentfile_alternative.currentextention'
Thanks,
James
Save Current File As with addition to filename
-
- Posts: 2
- Joined: Wed Aug 17, 2016 1:11 pm
-
- Posts: 2
- Joined: Wed Aug 17, 2016 1:11 pm
Re: Save Current File As with addition to filename
THought I'd got there with the below, but no luck!
#target photoshop
var doc = app.activeDocument;
var docName = doc.name;
docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/):docName = [docName, docName];
var suffix = '_example';
var saveName = new File(decodeURI(doc.path)+'/'+docName[1]+suffix);
var saveJPEG = File(app.activeDocument, saveName, 10);
#target photoshop
var doc = app.activeDocument;
var docName = doc.name;
docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/):docName = [docName, docName];
var suffix = '_example';
var saveName = new File(decodeURI(doc.path)+'/'+docName[1]+suffix);
var saveJPEG = File(app.activeDocument, saveName, 10);
Re: Save Current File As with addition to filename
Tips:
if not then use modified code for just created, but not saved yet document:
- don't use app. or there is really need as SOMETHING without app, so app.SOMETHING wouldn't work. As far as only SOMETHING == app.SOMETHING gives the result use the simplest form (or you have your reason to do it other way)
- it's alike variable (var). Maybe visually it's easier for beggining to use it (or loop some function code in source form for searching for variables), but after all you need it only untill some variable is undefined before it finally (or not) get same value during running the code
- you may also use one shorter line instead of two like "docName = activeDocument.name", or don't use even one line untill you won't recall the same "element", so value set to variable, however in early stage maybe it can be more readable for 3rd person coders
Code: Select all
jpg = new JPEGSaveOptions, jpg.quality = 10;
(aD = activeDocument).saveAs(File((aD.path) + '/' + aD.name.replace(/(\.\w+$)/, '_alternative$1')), jpg)
Code: Select all
$.level = 0, jpg = new JPEGSaveOptions, jpg.quality = 10;
try{(aD = activeDocument).saveAs(File((aD.path) + '/' + aD.name.replace(/(\.\w+$)/, '_alternative$1')), jpg)}
catch (err) {alert('Save your file before checking its path!')}
- Attachments
-
- File Saving.zip
- (453 Bytes) Downloaded 743 times
Re: Save Current File As with addition to filename
Thanks Kukurykus
This script is what I needed to add another.
Thanks a million.
PD
Thank God. I could find the Forum.
It was, missing.
Why? It has been so long out of network
This script is what I needed to add another.
Thanks a million.
PD
Thank God. I could find the Forum.
It was, missing.
Why? It has been so long out of network
Re: Save Current File As with addition to filename
I'm glad it helped. I remember when such short codes were valuable for me, but now are just some regular ones I use in programs quite often.
- DavideBarranca
- Posts: 16
- Joined: Tue Jul 26, 2016 2:12 pm
Re: Save Current File As with addition to filename
Actually I wouldn't suggest (especially to beginners) to skip "var" altogether, see here. Just my own point of view
Cheers,
Davide
Cheers,
Davide
Re: Save Current File As with addition to filename
Now I understand why some variables in / out functions could spoil my fun But I thought problem of local / global variables was solved in later versions of JavaScript. Later I'll examine it for sure...
- DavideBarranca
- Posts: 16
- Joined: Tue Jul 26, 2016 2:12 pm
Re: Save Current File As with addition to filename
Well, ES6 introduces "let" as a locally scoped "var", but remember that when it comes to ExtendScript we're stuck to EcmaScript version 3, i.e. pre-2009.
We're... vintage
Davide
We're... vintage
Davide