Help With HTML Panel
Copy link to clipboard
Copied
Figured it out. 🙂
Explore related tutorials & articles
Copy link to clipboard
Copied
Repost then your request and share the solution 😉
Copy link to clipboard
Copied
I thought I had fixed this but I havent so I am throwing it out to the experts for some help.
In the html panel, I have a Combo Box. If the user chooses Excel, it open up a MS Excel file and if the user chooses Numbers, it opens up an Apple numbers file. Both of these reside in a subfolder of the extension panel.
I am using csInterface.getSystemPath(SystemPath.EXTENSION) to get the path to the files
I am using csInterface.evalScript to execute the file.
The user is prompted to make sure they want to do this. The prompt is coming from the photoshop.jsx file
HTML (index.html)
var result = confirm ("This Will Open Apple Numbers\nAre you Sure?","");
if(result === true){
return result;
}
else if (result === false) {
return result;
}
Copy link to clipboard
Copied
I thought I had fixed this but I havent so I am throwing it out to the experts for some help.
In the html panel, I have a Combo Box. If the user chooses Excel, it open up a MS Excel file and if the user chooses Numbers, it opens up an Apple numbers file. Both of these reside in a subfolder of the extension panel.
I am using csInterface.getSystemPath(SystemPath.EXTENSION) to get the path to the files
I am using csInterface.evalScript to execute the file.
The user is prompted to make sure they want to do this. The prompt is coming from the photoshop.jsx file
HTML (index.html)
<select id="spreadsheet">
<option value="">Choose Your Spreadsheet</option>
<option value="Excel">Microsoft Excel</option>
<option value="Numbers">Apple Numbers</option>
</select>
main.js
$("#spreadsheet").change(function() {
if($(this).val() == "Numbers") { //user chose numbers
csInterface.evalScript('Apple_Numbers()',function(result) { //call function in jsx file and bring back the result
if(result = "yes"){ //user chose yes from the prompt
var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION);
var extensionRoot = "" + extensionRoot + "/spreadsheet/"; //path to the file
var myfile="project1.numbers"; // File Name
csInterface.evalScript('File("' + extensionRoot + myfile +'").execute()'); //open the file
}
});
photoshop.jsx
function Apple_Numbers(){
var result = confirm ("This Will Open Apple Numbers\nAre you Sure?","");
if(result === true){
return result;
}
else if (result === false) {
return result;
}
Problem:
If I select No in the promp dialog, I am getting False returned back to the main.js file but yet it is is still executing the code
and I cannot see why.
Ian
Copy link to clipboard
Copied
You have at least two errors.
1. if (result = "yes") is always true, because you use the assignment "=" instead of comparing "==". Equivalent to if ("yes").
2. result according to your logic can be either true or false, but not "yes" in any way.
For deguging paste the first command into your function (before if) the code:
Copy link to clipboard
Copied
Adding alert(result);
before the if statement returns false if I choose No on the prompt the code doesnt run (which is good) but..
if I choose Yes on the prompt the alert gives me true and code does not run either.
Copy link to clipboard
Copied
Just try replacing
if (result = "yes")
to
if (result == true)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I am wondering if this is because I am working in the main.js file for Photoshop panel and it doesnot fully understand regular Javascript.
Copy link to clipboard
Copied
Show your full (original) code if you want.
Maybe you made a typo there that you didn’t notice.
Copy link to clipboard
Copied
this is is main.js
$("#spreadsheet").change(function() {
if($(this).val() == "Numbers") {
csInterface.evalScript('Apple_Numbers()',function(result) {
alert(result);
if(result == true){
alert("we are here")
}
});
}
});
Copy link to clipboard
Copied
To understand (I do not deal with extensions) I need all your extension (all files). If you do not mind.
Then I will try to run and figure it out for myself.
Just interesting already.
P.S. And what does the alert show? Can I see a screenshot?
Copy link to clipboard
Copied
I think I have fixed it but dont know why its working this way.
In the photoshop.jsx file I now have this.
I have declared a var as a string and then passed that string to the return
function Apple_Numbers(){
var result = confirm ("This Will Open Apple Numbers\nAre you Sure?",false,"");
if(result === true){
var open_numbers = "yes";
return open_numbers;
}
else if (result === false) {
var open_numbers ="no"
return open_numbers;
}
else {
alert ("Error");
}
back in main.js it now looks like this
$("#spreadsheet").change(function() {
if($(this).val() == "Numbers") {
csInterface.evalScript('Apple_Numbers()',function(result) {
alert(result);
if(result == "yes"){
alert("we are here")
}
});
}
});
Copy link to clipboard
Copied
In what was before - too.

