bialikover / vscode-to-photoshop

an extension for vscode to evaluate extend script in photoshop
12 stars 2 forks source link

[QUESTION]: Getting actual JavaScript file path #3

Open edwardfxiao opened 1 month ago

edwardfxiao commented 1 month ago

Hi, very useful project! But I am having trouble to get the real JavaScript file path

Right now when executing

var currentScriptFile = new File($.fileName);
alert(currentScriptFile.toString());

it outputs ~/.vscode/extensions/bialikover.vscode-to-photoshop-0.0.3/out/src/tmp_file.jsx, while the actual file is located in ~/my-photoshop/scripts/script-1.js, and I understand the logic behind.

But is it possible to get the actual path? Because I somehow need to load the action file(~/my-photoshop/actions/action-1.atn or../actions/action-1.atn for example) in different directory, and I would change the action directory or directory depth level from time to time.

edwardfxiao commented 1 month ago

I don't know about windows, but for macOS, you can replace

if (process.platform === OSX) {
    let script = `tell application id "com.adobe.Photoshop" to do javascript ("#include ${pathTojsx}")`;
    osascript.execute(script, cb);
}

to

if (process.platform === OSX) {
    let script = `tell application id "com.adobe.Photoshop" to do javascript ("#include ${pathTojsx}") with arguments "{filename: '${editor.document.fileName}'}"`;
    osascript.execute(script, cb);
}

Then I can get the filename like this:

if (typeof JSON === 'undefined') {
  var JSON = {
      parse: function (str) {
          return eval('(' + str + ')');
      }
  };
}
var actualFilename = "";
try {
  var option = JSON.parse(arguments[0]);
  actualFilename = option.filename;
}
catch(e){}
edwardfxiao commented 1 month ago

Till vscode-to-photoshop handle this,

I have created vscode-to-photoshop2-with-real-path if anyone has the same need.

Thanks again for this great extension @bialikover