Copy link to clipboard
Copied
Yesterday Loic asked me for an example of a script that would send the pdf file by mail.
Today I made it and decided to post it here on the forum — may be this will be interesting to somebody.
It exports the frontmost document to pdf file using [Smallest File Size] preset, then opens it in acrobat, sends it in the attachment to this e-mail address: someone@somewhere.com (please change it) and finally closes the file.
I tested it on CS3 for Windows, but I can't send e-mails from my Mac. Can anybody test it on Mac?
Kasyan
#target indesign
var myIndesignDoc = app.activeDocument;
var myParentFolder = myIndesignDoc.fullName.parent;
var myBaseName = GetFileNameOnly(myIndesignDoc.name);
var myFilePath = myParentFolder.absoluteURI + "/" + myBaseName + ".pdf";
var myFile= new File(myFilePath);
myIndesignDoc.exportFile( ExportFormat.pdfType, myFile, false, "[Smallest File Size]" );
var myScript = AcrobatScript.toString() + '\r';
myScript += 'AcrobatScript(\"' + myFilePath + '\");';
var bt = new BridgeTalk;
bt.target = "acrobat";
bt.body = myScript;
bt.send();
function AcrobatScript(myFilePath) {
var myAcrobatDoc = app.openDoc(myFilePath);
myAcrobatDoc.mailDoc({
bUI: false, // don't show dialog box
cTo: "someone@somewhere.com", // e-mail address
cSubject: "This message was sent you by script", // subject line
cMsg: "Here goes some message text."// message body
});
myAcrobatDoc.closeDoc( true );
}
function GetFileNameOnly(myFileName) {
var myString = "";
var myResult = myFileName.lastIndexOf(".");
if (myResult == -1) {
myString = myFileName;
}
else {
myString = myFileName.substr(0, myResult);
}
return myString;
}
Copy link to clipboard
Copied
I can't seem to make it work. It produces a PDF but then I don't see any activity or emailing it seems.
CS3 and Acro 8 and Acro 9
Copy link to clipboard
Copied
I've found the reason why it doesn't work on Mac: Acrobat is not a messaging-enabled application on Mac ( it is on Windows).
You can test it by running this line:
BridgeTalk.getSpecifier("acrobat");
==> acrobat-8.0 -- on Windows
==> null -- on Mac
or you can get the list of messaging-enabled application:
BridgeTalk.getTargets();
on Windows, Acrobat is in the list:
acrobat,bridge,devicecentral,dreamweaver,estoolkit,illustrator,indesign,photoshop,stockphotos
but on Mac, it's missing
Copy link to clipboard
Copied
Kasyan,
Thanks for sharing this useful script. However, I can't get it to work because apparently Acrobat doesn't like my email program. After the PDF is created and loaded in Acrobat, nothing happens. When I try to attach the PDF manually (File > Attach to Email), Acrobat says ""Acrobat is unable to connect to your email program." I've poked around in the preferences but can't seem to find any way to tell Acrobat what my email program is (Opera's mail client). Any idea?
Another thing: to construct the PDF name for the current document, could you not simply say the following?
myFilePath = String (myIndesignDoc.fullName).replace (/indd$/, "pdf");
Thanks,
Peter
Copy link to clipboard
Copied
myFilePath = String (myIndesignDoc.fullName).replace (/indd$/, "pdf");
Kasyan is careful not to mess up a filename without its extension
Yours may be a bit better if you use this (untested!)
myFilePath = String (myIndesignDoc.fullName)+".indd";
myFilePath = String (myIndesignDoc.fullName).replace (/\.indd(\.indd)?$/, "pdf"); (oops)
myFilePath = myFilePath.replace (/\.indd(\.indd)?$/, "pdf");
to always make sure the original name ends with ".indd".
Copy link to clipboard
Copied
> Kasyan is careful not to mess up a filename without its extension
Have you ever seen an InDesign file without .indd extension?
Peter
Copy link to clipboard
Copied
I trained my (primarily Mac!) co-workers not to. Usually by shouting until they promised never to do it again.
I have seen lots of files without extensions -- all made on Mac's, of course, and predating OS X. It takes some binary-viewing and inspired guesswork to get hold of the original type.
Copy link to clipboard
Copied
Peter,
I use Microsoft Office Outlook 2007 — it works for me.
JavaScript for Acrobat API Reference says on page 130:
"Note: On Windows: The client machine must have its default mail program configured to be MAPI enabled to use this method".
I have vague idea about what that means, but may be it is your Opera's mail client that should be adjusted.
My co-workers, sometimes, on rare occasions, contrive to make indd file names without extension, so I consider my approach to be more fool proved.
Kasyan
Copy link to clipboard
Copied
Thanks, Kasyan. I'll give that a shot.
If people save ID files without extension then your method is much better, naturally. Though how you can save an ID doc without extension (or an extension other than indd) isn't clear to me (not am I particularly interested). So they change the file's name after saving it?
Peter
Copy link to clipboard
Copied
Peter,
Your code is good, I like it because it's more concise— btw, I'm a fanatical adherent of the compact code. Working on Mac, I don't care much if a file has an extension — it opens with or without it. But sometimes one of my scripts throws an error and it turns out that it's caused by missing extension. In the office, we all work on a network drive sitting in different rooms, so I have no idea how they do this: name or rename — I just take into account that the extension may be missing. But your one line code would work for me in 99,999999999999% of cases, so it's practically equivalent.
Kasyan
Copy link to clipboard
Copied
Hello Kasyan,
>I'm a fanatical adherent of the compact code
Good! I see your point about the possibility of extensionless file names (even if the chance is remote), but even then your code can be made more compact:
myFilePath = String (myIndesignDoc.fullName)
if (myFilePath.slice (-5) == ".indd")
myFilePath = myFilePath.replace (/indd$/, "pdf");
else
myFilePath += ".pdf";
Peter
Copy link to clipboard
Copied
Thank you, Peter.
I'll certainly use your tip in my scripts.
Kasyan
Copy link to clipboard
Copied
On a Mac it's very, very easy to save without an extension. Just change this:
to this:
and Walla! you have a file that Windows will not have the slightest idea what to do with...
It's not good practice, but there's nothing at all to stop the un-educated from doing it!
Harbs
Copy link to clipboard
Copied
Hi all,
First of all, thanks a lot Kasyan for your example.
(Other people, don't worry I have already sent thanks to him in private a few weeks ago 😉 )
So now I could take some time to handle it. But whatever I try, all my attempts are unsuccessful. Even the most simple function such as app.alert("foo") doesn't work. It's like Indesign didn't communicate at all with Acrobat.
It's very annoying but it's doesn't matter so much. I was working on a script for which that ability would have a nice feature but that's ok. I am just upset to deal with things that work with some people but not the others 😞
I am starting to remember why i carefully avoid scripting Acrobat
To be constructive, I made my tests on a Windows XP, Acrobat 9 and CS4. In case these datas can be a clue.
Loic
Copy link to clipboard
Copied
Did you try to run BridgeTalk.getSpecifier("acrobat"); in ESTK? What does it return?
When you run BridgeTalk.getTargets(); is acrobat in the list?
Copy link to clipboard
Copied
Hello, Kasyan!
When I run BridgeTalk.getTargets() in ESTK on my MacBook Pro OS X 10.5.8 I'm not getting "Acrobat". I get the following list:
fireworks
ame
bridge
devicecentral
dreamweaver
estoolkit
exman
flash
illustrator
indesign
photoshop
stockphotos
You might wonder what applications like "ame" and "exman" might be: ame is Adobe Media Encoder, but I'm not sure about "exman".
Copy link to clipboard
Copied
...but I'm not sure about "exman"
My guess is that this is Extension Manager.
...on my MacBook Pro OS X 10.5.8 I'm not getting "Acrobat"...
It's strange for me that this feature is supported on one platform and not on the other.
Kasyan
Copy link to clipboard
Copied
I have the same items on my mac, can 't test it on PC before monday.
Thx for all.
Loic
Copy link to clipboard
Copied
Hi all,
Here is the result on a PC
CS3 :
fireworks,acrobat,ame,bridge,contribute,devicecentral,dreamweaver,estoolkit,exman,flash,illustrator,incopy,indesign,photoshop,stockphotos,switchboard
CS4:
fireworks,acrobat,ame,bridge,contribute,devicecentral,dreamweaver,estoolkit,exman,flash,illustrator,incopy,indesign,photoshop,stockphotos,switchboard
So acrobat is part of the list but I can't get it doing anything, argh.
Whatever, even if I get it running well on PC, the fact is not event working on mac broke the charm.
Thx again Kasyan.
Loic
Copy link to clipboard
Copied
Is Opera Mail your Window Default Email client. If not goto Control Panel -> Internet Options -> Programs tab -> E-Mail on WinXP or something similar on Vista or Win7
Copy link to clipboard
Copied
Steven,
Opera is the default email program. But anyhow, it's not terribly important.
Thanks,
Peter
Copy link to clipboard
Copied
Thanks Kasyan! you have done a great help to me. I have tried your script and it works fine till generating pdf. My requirement is little different. I have a field called "Email" in pdf and a action to set for that button to attach with email.
#target indesign
var myIndesignDoc = app.activeDocument;
var myParentFolder = myIndesignDoc.fullName.parent;
var myBaseName = GetFileNameOnly(myIndesignDoc.name);
var myFilePath = myParentFolder.absoluteURI + "/" + myBaseName + ".pdf";
var myFile= new File(myFilePath);var mylayerText = myIndesignDoc.layers.item("Text")
var mylayerGraphics = myIndesignDoc.layers.item("Graphics")
var mylayerOnlinePdf = myIndesignDoc.layers.item("Online PDFs")
var mylayerTagline = myIndesignDoc.layers.item("Print tagline")mylayerText.visible = true
mylayerGraphics.visible = true
mylayerOnlinePdf.visible = true
mylayerTagline.visible = falsevar myPDFExportPreset = app.pdfExportPresets.item("EBLowRes");
app.activeDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);//myIndesignDoc.exportFile( ExportFormat.pdfType, myFile, false, "[Smallest File Size]" );
var myScript = AcrobatScript.toString() + '\r';
myScript += 'AcrobatScript(\"' + myFilePath + '\");';
var bt = new BridgeTalk;
bt.target = "acrobat-9.0";
bt.body = myScript;
bt.send();
function AcrobatScript(myFilePath) {
var myAcrobatDoc = app.openDoc(myFilePath);
//app.execMenuItem("Email");
var f = myAcrobatDoc.getField("Email", "button");
f.setAction("MouseUp", "myAcrobatDoc.mailDoc(true);" );
//myAcrobatDoc.mailDoc({
// bUI: false, // don't show dialog box
// cTo: "someone@somewhere.com", // e-mail address
//cSubject: "This message was sent you by script", // subject line
//cMsg: "Here goes some message text."// message body
//});
myAcrobatDoc.closeDoc( false );
}
function GetFileNameOnly(myFileName) {
var myString = "";
var myResult = myFileName.lastIndexOf(".");
if (myResult == -1) {
myString = myFileName;
}
else {
myString = myFileName.substr(0, myResult);
}
return myString;
}
I tried this little modified code and it generates the pdf but does not set action for that particular button.
The code I am using in Acrobat to set action is
var f = this.getField("Mail", "button");
f.setAction("MouseUp", "this.mailDoc(true);" );
Rather than going to Acrobat and run this script manually is this possible to combine this action within Indesign script?
Please help me.
Regards,
Muthuraj. D
Copy link to clipboard
Copied
Rather than going to Acrobat and run this script manually is this possible to combine this action within Indesign script?
if you're on Mac not , if on Windows -- most probably yes. Which version of InDesign do you use?
Kasyan
Copy link to clipboard
Copied
Hi Kasyan, Thanks for your quick reply.
I am using Windows, Indesign CS4 and Acrobat 9 Pro Extended. I hope I am lucky to get the solution
Copy link to clipboard
Copied
Could you send me a sample InDesign document so I could test your script on it? My e-mail is askoldich [at] yahoo [dot] com.
I have CS3 installed on my Windows machine -- hope it would work the same way as on CS4.
Kasyan