Copy link to clipboard
Copied
I have some code I've written and links to the tools button. However the SaveAs function errors as it suggests that it is not defined. I am running this script as a folder-level script. I have pasted the script i am using below. Can anyone help me with this or suggest me on what to do?
var Subject
var aDocumentFileName = this.documentFileName;
var dialog1 =
{
initialize: function (dialog) {
var todayDate = dialog.store()["date"];
todayDate = "Date: " + util.printd("mmmm dd, yyyy", new Date());
dialog.load({ "date": todayDate });
},
commit:function (dialog) {
var results = dialog.store();
Subject = results["fnam"];
aDocumentFileName = results["lnam"];
},
description:
{
name: "Subject",
align_children: "align_left",
width: 350,
height: 200,
elements:
[
{
type: "cluster",
name: "File Entry",
align_children: "align_left",
elements:
[
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "Case Reference: "
},
{
item_id: "fnam",
type: "edit_text",
alignment: "align_fill",
width: 283,
height: 20
}
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "Save File as : "
},
{
item_id: "lnam",
type: "edit_text",
alignment: "align_fill",
width: 300,
height: 20
}
]
},
{
type: "static_text",
name: "Date: ",
char_width: 25,
item_id: "date"
},
{
alignment: "align_left",
type: "ok_cancel",
ok_name: "Save",
cancel_name: "Cancel"
},
]
},
]
}
};
var myTrustedTool = app.trustedFunction(function(name)
{
app.beginPriv();
app.execDialog(name);
app.endPriv();
});
mySaveAs = app.trustPropagatorFunction(function(doc,path) {
app.beginPriv();
doc.saveAs(path);
app.endPriv();
});
myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path) {
// Privileged and/or non-privileged code above
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
// Privileged and/or non-privileged code below
});
if ("ok" == app.execDialog(dialog1)){
// build file name
var myFileName = "aDocumentFileName -" + "Subject" + ".pdf";
// add folder name
myFileName = "/c/documents/" + myFileName
myTrustedSpecialTaskFunc(this, myFileName);
};
app.addToolButton(
{
cName: "DialogueBox3",
cUser: "My Menu",
cParent: "Tools",
cLabel: "Dialogue3",
cExec: "myTrustedTool(dialog1);",
cEnable: "event.rc = app.doc;"
});
Thanks
Copy link to clipboard
Copied
The code that calls the function needs to be embedded in the file itself. When the application is first opened, and the folder-level script is executed, there are no files open, even if it was opened by double-clicking a file.
Copy link to clipboard
Copied
can you provide an example of this, as It is still not working for me when creating the function inside the document.
Thanks
Copy link to clipboard
Copied
What code did you put in the folder-level, and what code in the doc-level, and what happens when you open the file?
Copy link to clipboard
Copied
I have put this in the folder-level
var Subject
var aDocumentFileName = this.documentFileName;
var dialog1 =
{
initialize: function (dialog) {
var todayDate = dialog.store()["date"];
todayDate = "Date: " + util.printd("mmmm dd, yyyy", new Date());
dialog.load({ "date": todayDate });
},
commit:function (dialog) {
var results = dialog.store();
Subject = results["fnam"];
aDocumentFileName = results["lnam"];
},
description:
{
name: "Subject",
align_children: "align_left",
width: 350,
height: 200,
elements:
[
{
type: "cluster",
name: "File Entry",
align_children: "align_left",
elements:
[
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "Case Reference: "
},
{
item_id: "fnam",
type: "edit_text",
alignment: "align_fill",
width: 283,
height: 20
}
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
type: "static_text",
name: "Save File as : "
},
{
item_id: "lnam",
type: "edit_text",
alignment: "align_fill",
width: 300,
height: 20
}
]
},
{
type: "static_text",
name: "Date: ",
char_width: 25,
item_id: "date"
},
{
alignment: "align_left",
type: "ok_cancel",
ok_name: "Save",
cancel_name: "Cancel"
},
]
},
]
}
};
var myTrustedTool = app.trustedFunction(function(name)
{
app.beginPriv();
app.execDialog(name);
app.endPriv();
});
if ("ok" == app.execDialog(dialog1)){
// build file name
var myFileName = "aDocumentFileName -" + "Subject" + ".pdf";
// add folder name
myFileName = "/c/temp/" + myFileName
myTrustedSpecialTaskFunc(this, myFileName);
};
app.addToolButton(
{
cName: "DialogueBox3",
cUser: "My Menu",
cParent: "Tools",
cLabel: "Dialogue3",
cExec: "myTrustedTool(dialog1);",
cEnable: "event.rc = app.doc;"
});
I have put this in the doc-level
mySaveAs = app.trustPropagatorFunction(function(doc,path) {
app.beginPriv();
doc.saveAs(path);
app.endPriv();
});
myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path) {
// Privileged and/or non-privileged code above
app.beginPriv();
mySaveAs(doc,path);
app.endPriv();
// Privileged and/or non-privileged code below
});
When i open the document, the dialogue box appears and once i press the save. It closes the dialogue box and doesn't save.
Copy link to clipboard
Copied
You got it all wrong, I'm afraid. Put the dialog definition and the if-statement at the doc-level and the trusted functions and the command to add a new toolbar button at the folder-level.
Copy link to clipboard
Copied
Trusted functions at doc-level makes no sense.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now