Copy link to clipboard
Copied
Hi, this is my first time posting here, and I wanted ask jsx scripting.
I'm trying to apply the code reading Photoshop JavaScript Reference page 76.
// Open the document in the script
var fileRef = new File("/c/myfile")
var docRef = app.open(fileRef)
//Call emboss with desired parameters
emboss( 75, 2, 89 );
//finish the script
//include the function in the script file
function emboss(angle, height, amount )
{
var id32 = charIDToTypeID( "Embs" );
var desc7 = new ActionDescriptor();
var id33 = charIDToTypeID( "Angl" );
desc7.putInteger( id33, angle );
var id34 = charIDToTypeID( "Hght" );
desc7.putInteger( id34, height );
var id35 = charIDToTypeID( "Amnt" );
desc7.putInteger( id35, amnt );
executeAction( id32, desc7, DialogModes.NO );
}
But I got the error code:
Error 1233: Expected a reference to an existing File/Folder Line:3
-> var docRed = app.open(fileRef)
Could you give me some advice on what to fix this code?
I'm using latest version Photoshop2020.
Hello, welcome. 🙂
the first line points to a file on your computer.
var fileRef = new File("/c/myfile")
If that file does not exist at that location, it cannot be opened.
By changing the fileRef string (that's this part: "/c/myfile") to a file that does exist, it will work.
You could for example change it to "c:\mochisan.jpg" or "d:\these\are\folders\picture.png".
If those files exist, the script/photoshop will find them.
Copy link to clipboard
Copied
Hello, welcome. 🙂
the first line points to a file on your computer.
var fileRef = new File("/c/myfile")
If that file does not exist at that location, it cannot be opened.
By changing the fileRef string (that's this part: "/c/myfile") to a file that does exist, it will work.
You could for example change it to "c:\mochisan.jpg" or "d:\these\are\folders\picture.png".
If those files exist, the script/photoshop will find them.
Copy link to clipboard
Copied
Thank you very much for your help. But the same error is returend😭
Copy link to clipboard
Copied
I've tested your code this time (instead of just reading it as in my initial reply)
You're right, it does not work as-is.
This rewritten code works on my computer:
#target photoshop;
// Open the document in the script
var fileRef = new File("/Users/JB/Desktop/d.jpg"); // <-- change this
var docRef = app.open(fileRef);
emboss( 75, 2, 89 );
//function in the script file
function emboss(angle, height, amount )
{
var ADEmboss = new ActionDescriptor();
ADEmboss.putInteger( charIDToTypeID( "Angl" ), angle );
ADEmboss.putInteger( charIDToTypeID( "Hght" ), height );
ADEmboss.putInteger( charIDToTypeID( "Amnt" ), amount ); // there was a typo here
executeAction( charIDToTypeID( "Embs" ), ADEmboss, DialogModes.NO );
}
Change the green part > "Users/JB/Desktop/d.jpg" < to a path of a picture stored on your computer and it should work.
Note: You cannot load a picture from the internet this way.
This:
var fileRef = new File("http://www.myawesomepictures.com/images/ForMochisan.jpg");
Does not work. And it gives you the same error as you initially had.
Lastly, p76 in that pdf talks about channels, nothing related to loading files or Emboss.
Am I missing something?
Copy link to clipboard
Copied
I'm so sorry! Photoshop Scripting Guide page 76 is right.
Your code works on my computer! Thank you very much!
Copy link to clipboard
Copied
Don't worry about it. We all need to learn from the beginning.
While you are here, you'll find a lot of very helpful people here that have told me the same thing not too long ago. 🙂 I'm happy for you it works, good luck!!!