I'm trying to automate data merge process. Here's what I have:
First of all have created a working datamerge script:
function main(){
mySnippet ();
myTeardown();
}
//<setup>
//<snippet>
function mySnippet(){
// automate datamerge
var myDocument = app.open(File("P:/RxCut/In Design Implementation/build/automate/automate.indd"));
var myDataSource = File("P:/RxCut/In Design Implementation/build/automate/automate.txt");
myDocument.dataMergeProperties.selectDataSource(myDataSource);
myDocument.dataMergeProperties.mergeRecords();
myDocument=myDocument.save("P:/RxCut/In Design Implementation/build/automate/AutomatedMerged.indd");
app.activeDocument.save(new File("P:/RxCut/In Design Implementation/build/automate/AutomatedMerged2.indd"));
myDocument.close();
}
//</snippet>
//<teardown>
function myTeardown(){
}
This runs great as expected!
Then had to write a vbscript to open InDesign and run that jsx script above:
Set myInDesign = CreateObject("InDesign.Application.CS5")
Msgbox("This message from Vbscript")
myJavaScript = "C:\test2.jsx"
myInDesign.DoScript myJavaScript, 1246973031
Now if CreateObject("InDesign.Application.CS5") opens InDesign how to close it?
app.quit();
easy as that
app.open
to open
app.quit
to quit
Related
Please tell me how do I click in point coordinates in application window?
I trying to UI automate my application on OSX 10.10 using JXA technology.
In documentation I found that it's possible using click at event. By I'am beginner of JXA and cant find how make a call.
Code snippet which I tried in Script Editor:
var app = Application('my_application_path')
app.window.click.at('{100,100}')
Thank you for help
You can interact with an application's user interface using the System Events application. Here is a script that clicks at certain coordinates in Safari:
// Activate Safari, so you will be able to click like a user
Application("Safari").activate()
// Access the Safari process of System Events
var SystemEvents = Application("System Events")
var Safari = SystemEvents.processes["Safari"]
// Call the click command, sending an array of coordinates [x, y]
Safari.click({ at: [300, 100] })
If you want to click a specific button (or other element of the user interface), it is more appropriate to click that specific element. For example:
// Click the third button of Safari's first window to minimize it
Safari.windows[0].buttons[2].click()
To learn what user interface elements can be interacted with and how, check out the Processes Suite in System Events' scripting dictionary. To open the dictionary, in Script Editor's menu bar, choose Window > Library, then select System Events in the Library window.
See https://github.com/dtinth/JXA-Cookbook/wiki/System-Events#clicking-menu-items
For example:
var fileMenu = proc.menuBars[0].menuBarItems.byName('File');
Below is an example of a portion of a script I wrote that automates creating mailboxes (aka folders) in Mail. I ended up using the UI file menus and click because using make() in the Mail DOM had issues for me. Hope it helps someone.
(() => {}
//this is part of a script that automates creating mailboxes (ie folders) in Apple Mail
//I used the file menu UI because when I tried the Mail library and make() method
//there was strange behavior when trying to interact with the new mailbox.
//However, when creating the new mailboxes thru the file menu, all seems to work fine
const Mail = Application('Mail');
const strId = Mail.accounts.byName('Exchange').id();
const exchange = Mail.accounts.byId(strId);
const activeClientFolder = exchange.mailboxes.byName('ActiveClient');
const SysEvents = Application('System Events');
const mail = SysEvents.processes.byName('Mail');
//next two lines insure Mail will be open and in front
mail.windows[0].actions.byName('AXRaise').perform();
mail.frontmost = true;
const mailboxMenu = mail.menuBars[0].menus.byName('Mailbox');
//below shows EXAMPLES of using .click(), keystroke(), and keyCode()
let newFolder = function (parentFolder, newFolderName, addTrailingDelay = true) {
//next line will select the parent mailbox (aka folder) where the new mailbox will be inserted
Mail.messageViewers[0].selectedMailboxes = parentFolder;
mailboxMenu.click();
delay(.2);
mailboxMenu.menuItems.byName('New Mailbox…').click();
delay(.2);
SysEvents.keystroke(newFolderName);
SysEvents.keyCode(36);
//delay is needed when creating multiple mailboxes with a loop
if (addTrailingDelay == true){
delay(1);
}
}
//now the payoff
const count = newActiveClients.length;
for(let i=0;i<count;i++){
/* Client Root Mailbox */
newFolder(activeClientFolder, newActiveClients[i], true);
/* Client Email Folders */
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]), 'Client', true);
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]).mailboxes.byName('Client'), 'Client_FYI_Sent');
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]).mailboxes.byName('Client'), 'Client_FYI_Inbox');
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]).mailboxes.byName('Client'), 'Client_FYI_Client_To');
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]).mailboxes.byName('Client'), 'Client_From', false);
}
})()
I am trying to print pdf silently using adobe reader.
I have taken the example from the following location:
http://www.codeproject.com/Tips/598424/How-to-Silently-Print-PDFs-using-Adobe-Reader-and
I am able to work as desired with the above example code in my localhost.
But when I deploy my application on the server,I am unable to print the PDFs.
In my localhost on button click event,I am creating the PDFs and saving it to one location and printing the same.While printing adobe window opens and prints the PDFs and exits automatically.
The same doesn't work in my server.I am able to create and save PDFs,but adobe is not opening and printing my file.I am not even getting any exception/error.It simply doesn't show up adobe window.
Did anyone face the same issue.
Any help in this regard.
Thanks in advance.
EDIT:
If you are running on a Web Server using ASP.NET or in general IIS the new process executes on the Web server with restricted permissions. I point you out this answer that could explain the cause of your problem.
However the code you are using doesn't print any error message. You probably don't have access to the directory where the AcroRd32.exe is located.
Let's take this function from the article you posted:
public static Boolean PrintPDFs(string pdfFileName)
{
try
{
Process proc = new Process();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";
//Define location of adobe reader/command line
//switches to launch adobe in "print" mode
proc.StartInfo.FileName =
#"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = String.Format(#"/p /h {0}", pdfFileName);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
}
proc.EnableRaisingEvents = true;
proc.Close();
KillAdobe("AcroRd32");
return true;
}
catch
{
return false;
}
}
PrintPDFs uses a process, which is called by the .NET framework using the Process class. In the StartInfo option you look carefully two options are set:
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
The first redirect the standard output stream to your application while the second hides the cmd window. The former is handy to use process without showing to the user a command window but the latter hide the console window. The main drawback is, if you're debugging, that you probably won't see error coming through.
One way to debug it would require to add the following to lines:
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
Console.WriteLine(proc.StandardOutput.ReadToEnd());
Another property you can look at is ExitCode. If that is greather than zero means that your process exit with some error.
hope it helps.
A silent printing can be achieved with an Acroread command line parameters or with a PDF JavaScript event handler (of course, if your PDF producer tool has a possibility to define/inject PDF's OpenAction handler).
See http://pd4ml.com/cookbook/pdf_automated_printing.htm
With the JavaScript approach you are not bound to a printer driver, network name or IP address. On the other hand, JavaScript in Acroread can be disabled, for example, by a corporate security policy.
use this with Ghostscript that is GNU:
ProcessStartInfo info = new ProcessStartInfo();
var FileName = #"C:\ResultadoFormulario_CClastMovements.pdf";
var pathPrinter = #"\\Server\namePrinter";
info.CreateNoWindow = true;
var pathGsw = #"path gswin64c here\";
info.WindowStyle = ProcessWindowStyle.Hidden;
string strCmdText = $"{pathGsw}gswin64c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -dNOPROMPT -dNoCancel -dPDFFitPage -sOutputFile=\"%printer%{direccionImpresora}\" \"{FileName}\"";
Process.Start("CMD.exe", strCmdText);
As one of the outputs from an Extendscript, I want to create a shell script which can then be executed by the user. Here is a very basic example:
function createShellScript()
{
var contents = "#!/bin/bash\ndate";
var outputFolder = Folder.selectDialog ("Choose where to save:");
var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
shFile.open("W");
shFile.write(contents);
shFile.close();
}
createShellScript ();
If I take the resulting file (shell.sh), run chmod +x on it to make it exectuable, and then run it, nothing happens.
If, however, I adjust the script above to create the same content but a text file – so it outputs shell.txt open the file, copy the contents into a blank document in a code editor, and save as a .sh file, and then chmod and run it, it works fine.
Why does Extendscript not produce a proper .sh file when using this method?
Thanks for any help.
S
You need to set the line feed characters to unix style. For example, shFile.lineFeed = "Unix";.
function createShellScript()
{
var contents = "#!/bin/bash\ndate";
var outputFolder = Folder.selectDialog ("Choose where to save:");
var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
shFile.open("W");
shFile.lineFeed = "Unix";
shFile.write(contents);
shFile.close();
}
createShellScript ();
I use a script which opens the story editor like this:
app.menuActions.itemByID(119793).invoke();
How can I close it programmatically? How can I detect whether it's opened or closed?
A story editor window may be closed with its close method.
Here is a function which closes the story editor window if it's open. It tests for the presence of a zoom property on the window to determine whether the window is a story editor or not (Thanks Loic Aigon for this idea)... There must be a better way of doing this but I haven't found it.
function closeStoryEditor() {
var windows = app.activeDocument.windows,
nbWindows = windows.length,
i,
closedWindow = false;
for (i = 0; !closedWindow && i < nbWindows; i += 1) {
if (!windows[i].hasOwnProperty("zoom")) {
// Let us presume that a window without a zoom method is a story editor window...
windows[i].close();
closedWindow = true;
}
}
}
To close it, it's…the same call ! if you want to check if the editor is already opened, you can loop through all open windows like this :
app.activeDocument.windows.everyItem().name;
and see for matches.
Loic
http://www.loicaigon.com
I am porting some AutoCAD VBA to VB.Net.
Several of the modules do a ThisDrawing.SendCommand("_color" & vbCR) to popup an AutoCAD color picker, then process the response by doing a ThisDrawing.GetVariable("CECOLOR") to get the selected color.
With .Net, the SendCommand does not execute until the program ends.
How can I get the AutoCAD color picker to execute inline in my code?
There is a ColorDialog class to do that. Here is some C# code:
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
var cd = new ColorDialog();
if (cd.ShowDialog() != DialogResult.OK) return;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("\nSelected color: " + cd.Color);