Copy link to clipboard
Copied
I found the script below on this site and I would like to get it working for me to see if it's what I'm trying to accomplish. I have it attached to an mouseUp action of a button and it pops out a window. I click to open a file and click OK and that's all it does. No opens any file. Would someone take a look at this script and show me what's wrong or what's not right? I sure would appreciate it. I just wanna see it, I feel it's so close to working. Thanks, folks.
The script:
var docType
var Dlg ={
description:
{
name: "Select File To Open",
elements:
[
{
type: "view",
elements:
[
{
item_id: "Hdr1",
name: "Select File To Open",
type: "static_text",
},
{
item_id: "Btn1",
name: "File1",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn2",
name: "File2",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn3",
name: "File3",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn4",
name: "File4",
type: "radio",
group_id: "rdgp",
}
]
},
{
type: "ok_cancel",
ok_name: "Open"
},
]
}
};
commit:function (dialog) { // called when OK pressed
var results = dialog.store();
if (results["Btn1"]) docType = 1;
else if (results["Btn2"]) docType = 2;
else if (results["Btn3"]) docType = 3;
else if (results["Btn4"]) docType = 4;
}
app.execDialog(Dlg);
if(docType==1){
app.openDoc("File1", this);
}
else if(docType==2){
app.openDoc("File2", this);
}
else if(docType==3){
app.openDoc("File3", this);
}
else if(docType==4){
app.openDoc("File4", this);
}
Copy link to clipboard
Copied
To start with, use a full file DIPath in openDoc. Then, what does it say in console?
Copy link to clipboard
Copied
You have to add ".pdf" to the file-name.
Copy link to clipboard
Copied
I added the .pdf to the file name. It still doesn't open any of the files. Is there anything else, something I'm missing? This aspect of creating pdfs is very new to me. I hope to catch on with a bit more practice. All the pdf files are in the same folder on my desktop. This is the script thus far...
var docType
var Dlg ={
description:
{
name: "Select File To Open",
elements:
[
{
type: "view",
elements:
[
{
item_id: "Hdr1",
name: "Select File To Open",
type: "static_text",
},
{
item_id: "Btn1",
name: "File1",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn2",
name: "File2",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn3",
name: "File3",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn4",
name: "File4",
type: "radio",
group_id: "rdgp",
}
]
},
{
type: "ok_cancel",
ok_name: "Open"
},
]
}
};
commit:function (dialog) { // called when OK pressed
var results = dialog.store();
if (results["Btn1"]) docType = 1;
else if (results["Btn2"]) docType = 2;
else if (results["Btn3"]) docType = 3;
else if (results["Btn4"]) docType = 4;
}
app.execDialog(Dlg);
if(docType==1){
app.openDoc("TeBlank.pdf", this);
}
else if(docType==2){
app.openDoc("instrs.pdf", this);
}
else if(docType==3){
app.openDoc("schA.pdf", this);
}
else if(docType==4){
app.openDoc("schB.pdf", this);
}
Copy link to clipboard
Copied
What exactly happens when you run the code? Are there any error messages?
Copy link to clipboard
Copied
I ran it in the debugger and this message was at the end of the script. I hope I did it right.
SyntaxError: syntax error
1:Console:Exec
undefined
I saw in the post where I found this script you had answered as well. You mentioned moving the "commit:function" inside the dialog. I'm not sure about the phrasing. But, I don't know what that is or where to move it to. Do you know what I'm referring to? Would I have to do that here as well?
Copy link to clipboard
Copied
Add a semi-colon to the end of the first line.
And yes, the commit function has to be moved into the dialog object definition.
Basically, move it up one line, so the curly brackets that define the dialog object close after it.
Copy link to clipboard
Copied
well, I added the semi-colon at the end of the first line as you directed. But, I'm a bit lost as the commit function and moving it. I just don't know how many lines that entails? See the script below to see what I did. Where does the dialog object close? Could you direct me as to what to move and where to close it? Is that all that needs to be modified to get it to work? Here's what I've done.
var docType;
var Dlg ={
description:
{
name: "Select File To Open",
elements:
[
{
type: "view",
elements:
[
{
item_id: "Hdr1",
name: "Select File To Open",
type: "static_text",
},
{
item_id: "Btn1",
name: "File1",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn2",
name: "File2",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn3",
name: "File3",
type: "radio",
group_id: "rdgp",
},
{
item_id: "Btn4",
name: "File4",
type: "radio",
group_id: "rdgp",
}
]
},
{
type: "ok_cancel",
ok_name: "Open"
},
]
}
commit:function (dialog) { // called when OK pressed
var results = dialog.store();
if (results["Btn1"]) docType = 1;
else if (results["Btn2"]) docType = 2;
else if (results["Btn3"]) docType = 3;
else if (results["Btn4"]) docType = 4;
}
app.execDialog(Dlg);
};
if(docType==1){
app.openDoc("TeBlank.pdf", this);
}
else if(docType==2){
app.openDoc("instrs.pdf", this);
}
else if(docType==3){
app.openDoc("schA.pdf", this);
}
else if(docType==4){
app.openDoc("schB.pdf", this);
}
This is the message I get when I save and close out of TextWrangler editor - Javascript error at line 51: SyntaxError: missing } after property list 50
I don't know what that message means but I inserted }'s where I thought but it didn't help.