Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JSX - Open File in Photoshop

Engaged ,
Dec 29, 2021 Dec 29, 2021

Hi everybody,

 

I've been working on this for close to a day. I can't get a file to open in Photoshop no matter what I try to do with something thatI would imagine is relatievly straight-forward.

 

This is the script I'm using in VSCode:

 

// current file path
var filePath = new File($.fileName).parent;
alert(filePath); // works

var fileRef = filePath + "/PSD/test.psd";
alert("file in question: " +fileRef);
// file in question: "~/Documents/adobe_scripts/PSD/test.psd" 

alert(fileRef.exists); //undefined


var docRef = app.open(filePath);
 
// end of script
 
I keep getting 1230 and 1233 argument errors. I've tried to eval, toString, typeOf, trying to figure out why it just won't open...?
 
This is a basic direct reference to a path/file. Is there something right under my nose that I'm missing? If anybody could provide some insight I'd be thrilled.
 
Thanks!
-m
TOPICS
Actions and scripting
3.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 29, 2021 Dec 29, 2021

 

open(File(fileRef))

 

Translate
Adobe
LEGEND ,
Dec 29, 2021 Dec 29, 2021

 

open(File(fileRef))

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 29, 2021 Dec 29, 2021

Awesome, thank you!

 

(They should have that on Pg. 29 of the manual instead.) 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 29, 2021 Dec 29, 2021

I found 2 mistakes in your code:

 

- you tried to open a path (filePath)

- you used not an path object but string

 

btw if it solves the problem mark the solution as correct 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 29, 2021 Dec 29, 2021

Yes, it fixed the problem, thank you.

 

I thought I might be running into a datatype issue of some kind but it wasn't clear entirely what I was doing wrong. I managed to get an alert to tell me it was a string, so I tried to eval() it hoping it would 'get it'...no dice. 

 

So I needed to declare the File object by location reference, then pass the reference to the open command which is part of that objects method set. They explain that in the scripting guide, but it's example didn't work, yours did, strange. 

 

// works

var fileRef = new File($.fileName).parent+ "/PSD/test.psd";

var docRef = open(File(fileRef));

 

//does not

var fileRef = new File($.fileName).parent+ "/PSD/test.psd";

var docRef = app.open(fileRef);

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 29, 2021 Dec 29, 2021
LATEST

You simply missed out the File part and parentheses in the manual on said page 29.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines