Skip to main content
Moorphism LTD
Known Participant
December 13, 2021
Answered

$.evalFile execut the old script and the new one

  • December 13, 2021
  • 3 replies
  • 503 views

Hello, 

 

I build an extension to run script from its path, and i use $.evalFile("path/to/script") to do that, the idea is to find the right script depend on which button has been clicked, the problem is when i click on the first button, its script runs normally, but when i click on the second button the first script run and the second script also, then when i click on the third button, the two old scripts run and the new one also ... i don't know if Photoshop save the script on the cache or what's the problem, here's a snapshot on my code: 


var targetScriptPath = "path/to/script.jsx";
var targetScript = new File(targetScriptPath);
if (targetScript.exists) {
try {
$.evalFile(targetScript);
} catch (error) {
alert(error);
}
} else {
alert( "Missing Script File");
}

 

Any one can help me please?

Thanks on advance! 

This topic has been closed for replies.
Correct answer Stephen Marsh

The code you posted works fine:

 

var targetScriptPath = "~/Desktop/test-script.jsx";
var targetScript = new File(targetScriptPath);
if (targetScript.exists) {
try {
$.evalFile(targetScript);
} catch (error) {
alert(error);
}
} else {
alert( "Missing Script File");
}

 

test-script.jsx file on desktop:

 

app.beep();
alert('Success!');

 

I'm guessing that the error is in the UI code for what happens when a button is pressed, which has not been provided.

3 replies

Kukurykus
Legend
December 15, 2021
File(pth = '~/desktop/script.jsx').exists && $.evalFile(pth)
ajabon grinsmith
Community Expert
Community Expert
December 14, 2021

How is the event handler for each button written?

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
December 14, 2021

The code you posted works fine:

 

var targetScriptPath = "~/Desktop/test-script.jsx";
var targetScript = new File(targetScriptPath);
if (targetScript.exists) {
try {
$.evalFile(targetScript);
} catch (error) {
alert(error);
}
} else {
alert( "Missing Script File");
}

 

test-script.jsx file on desktop:

 

app.beep();
alert('Success!');

 

I'm guessing that the error is in the UI code for what happens when a button is pressed, which has not been provided.

Moorphism LTD
Known Participant
December 14, 2021

Yes i figure out the problem, it's in the UI side of my code, Thanks for your response 😄