Illegal filepath. Miss ")". Why?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Illegal filepath. Miss ")". Why?

Post by klevteev »

Hello!
I used a script to save a file on a certain path C:\Users\abcde\Desktop\temp, with adding unique numbers(think do texts through dialog box), until'm hammering manually each time.
So the script worked-worked... and then stopped, to speak omitted symbol of ")", although all is true. What's wrong?

Code: Select all

    var strtRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.MM;
    var docRef = app.activeDocument;
    filePath = docRef.path;
    
    var fileName = docRef.name.slice(".")

    var W = Math.round(docRef.width);
    var H = Math.round(docRef.height);
      
    function SaveAsTIFF( saveAsName ) {
       var tso = new TiffSaveOptions();
       tso.embedColorProfile = false;
       tso.imageCompression = TIFFEncoding.NONE;
       tso.byteOrder = ByteOrder.IBM;
       docRef.saveAs( File( saveAsName ), tso );
    }
    
	SaveAsTIFF ( C:\Users\abcde\Desktop\temp + ("001_" + W +"x" + H + "mm_" + fileName));

    docRef.close(SaveOptions.DONOTSAVECHANGES); //Fermer sans sauver
    app.preferences.rulerUnits = strtRulerUnits;
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Illegal filepath. Miss ")". Why?

Post by Kukurykus »

Code: Select all

C:\Users\abcde\Desktop\temp
should be:

Code: Select all

"C:\\Users\\abcde\\Desktop\\temp"
Last edited by Kukurykus on Fri Nov 08, 2019 2:29 pm, edited 1 time in total.
User avatar
Scriptor
Posts: 24
Joined: Tue Oct 01, 2019 12:07 pm

Re: Illegal filepath. Miss ")". Why?

Post by Scriptor »

Hi!
Try this - I've commented the changes I've done.

Code: Select all

var strtRulerUnits = app.preferences.rulerUnits;
	app.preferences.rulerUnits = Units.MM;
	var docRef = app.activeDocument;
	filePath = docRef.path;

	//var fileName = docRef.name.slice(".")
	var fileName = docRef.name.replace(/\.[^\.]+$/, '');	//Removes weird stuff and file extensions

	var W = Math.round(docRef.width);
	var H = Math.round(docRef.height);
	  
	function SaveAsTIFF( saveAsName ) {
		var tso = new TiffSaveOptions();
		tso.embedColorProfile = false;	//Note: Color profile is quite handy to include
		tso.imageCompression = TIFFEncoding.NONE;
		tso.byteOrder = ByteOrder.IBM;
		docRef.saveAs( File( saveAsName ), tso );
	}


	var tiffpath = new Folder("file:///c://Users//abcde//Desktop//temp");	//Sets directive to save image in
	var tiffname = "001_" + W +"x" + H + "mm_" + fileName;	//Sets name of image
	var fullpath = File(tiffpath + "/" + tiffname + '.tif');	//Combines path+name

	SaveAsTIFF (fullpath);

	docRef.close(SaveOptions.DONOTSAVECHANGES); 	//Fermer sans sauver
	app.preferences.rulerUnits = strtRulerUnits;
	
User avatar
Scriptor
Posts: 24
Joined: Tue Oct 01, 2019 12:07 pm

Re: Illegal filepath. Miss ")". Why?

Post by Scriptor »

Kukurykus wrote: Fri Nov 08, 2019 1:26 pm

Code: Select all

C:\Users\abcde\Desktop\temp
should be:

Code: Select all

"C:\\Users\\abcde\\Desktop\\temp"
Hands down - this is a more elegant solution :roll:
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Illegal filepath. Miss ")". Why?

Post by Kukurykus »

Let's see which answer klevteev will choose ;)
klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Re: Illegal filepath. Miss ")". Why?

Post by klevteev »

Thanks, but....
2019-11-11_17-40-09.png
2019-11-11_17-40-09.png (3.08 KiB) Viewed 7052 times
and...
2019-11-11_17-38-39.png
2019-11-11_17-38-39.png (4.49 KiB) Viewed 7052 times
:roll: :roll: :roll:

I have set a goal to enter through the numbering dialog, even understand... I know how to describe a numeric value, but assign it a text (use in the file name) does not work
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Illegal filepath. Miss ")". Why?

Post by Kukurykus »

The question is why did not you use " (closing quotation mark) after temp word in in the path?
klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Re: Illegal filepath. Miss ")". Why?

Post by klevteev »

Kukurykus wrote: Tue Nov 12, 2019 5:17 pm The question is why did not you use " (closing quotation mark) after temp word in in the path?
O my god! it`s work!!))) Thank`s a lot!!!
I didn't understand why - ), and I had to look - " :lol: :lol: :lol:

a little upgrade script: to enter the assigned number through the dialog box
But - new topic? or can suggest the right syntax

Code: Select all

var N = parseFloat (dlg.msgPnl.N.et.text);
But - numeric value, how do text?



All Script:

Code: Select all

    var strtRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.MM;
    var docRef = app.activeDocument;
    filePath = docRef.path;
    
    var fileName = docRef.name.slice(".")
var dlg = new Window('dialog', 'Number:');
dlg.frameLocation = [200, 200];

dlg.msgPnl = dlg.add('panel', undefined, 'Parametres');
dlg.msgPnl.alignChildren = "right";
dlg.msgPnl.N = dlg.msgPnl.add('group');

dlg.msgPnl.msgHeight = dlg.msgPnl.add('group');
dlg.msgPnl.selectFolder = dlg.msgPnl.add('group');

with (dlg.msgPnl) {
  N.st = N.add('statictext', undefined, 'Number:');
  N.et = N.add('edittext', undefined, '027');
  N.et.preferredSize = [80,20];

};

var bolUserCancel = false;
dlg.buttons2 = dlg.add('group');

dlg.buttons2.btnClose = dlg.buttons2.add("button",undefined , "Ok" );
dlg.buttons2.btnClose.onClick = function() { this.parent.close(0);  };
dlg.buttons2.btnCancel = dlg.buttons2.add("button",undefined , "Cancel" );
dlg.buttons2.btnCancel.onClick = function() { bolUserCancel = true; this.parent.close(0); };

dlg.show();

var N = parseFloat (dlg.msgPnl.N.et.text);

delete dlg;

    var W = Math.round(docRef.width);
    var H = Math.round(docRef.height);
      
    function SaveAsTIFF( saveAsName ) {
       var tso = new TiffSaveOptions();
       tso.embedColorProfile = false;
       tso.imageCompression = TIFFEncoding.NONE;
       tso.byteOrder = ByteOrder.IBM;
       docRef.saveAs( File( saveAsName ), tso );
    }

    SaveAsTIFF ("C://Users//klevteev//Desktop//temp//" + (N + W +"x" + H + "mm_" + fileName));
app.preferences.rulerUnits = strtRulerUnits;
klevteev
Posts: 17
Joined: Wed Nov 06, 2019 1:22 pm

Re: Illegal filepath. Miss ")". Why?

Post by klevteev »

Sorry!
sorted)

dlg.msgPnl.N.et.text - works
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Illegal filepath. Miss ")". Why?

Post by Kukurykus »

:)