I'm mixing javascript and imacros to automate some tasks.
The main JS file will do some stuff and go to my website in firefox. Then, the script check if the word "confirmation" is found
Here's what i have so far
var macro = "CODE:";
(...)
var big_count=parseFloat(prompt("how many loops ?",100));
for(var x=0;x<big_count;x++)
{
iimSet("rnd",Math.floor(Math.random()*2000 + 1));
iimPlay(macro);
if(window.content.document.body.textContent.contains('confirmation'))
{
//if confirmation word found
iimPlay("CODE:WAIT SECONDS=60");
}
else
{
//if confirmation word isn't found
}
}
If the confirmation word is found, i want to launch another .iim script. I know i can do this using the following:
iimPlay("myFile.iim")
But the user running the .JS file needs to be able to chose which .IIM file will be run at the end of the script. How can i do this ?
I need some sort of prompt dialog that will list all files inside the following folder:
C:\Users\Libertad\Documents\iMacros\Macros
Then when a file is selected, pass the file name to the iimPlay() function
Related
I am trying to make Photoshop tell me how many Files were opened in Photoshop.
Of course I can always go and check in finder, how mnay files I tried to open - but that is not always accurate, sometimes for unknown reason files are skipped. I could also go and count manually, although that takes very long. I've written a simple script which tells me how many file were opened.
if (!documents.length) alert("No Open documents");
else alert(documents.length + " images opened");
At the moment I simply put it into the action. I open all the files, 200 images, run the action - I receive a pop up message. It is great.
But is there a way to make it automatic? To make the script run only on the last file opened? How would I go about automating it?
Maybe you can use a script to open the files instead of Open command? The script will ask for files location as Open command normally would but in the end you can do whatever you want when files were opened.
var inputFiles = File.openDialog(undefined, undefined, true); //multiselect: true
if (inputFiles != null)
{
for (var i = 0; i < inputFiles.length; i++)
{
open(inputFiles[i]);
}
alert(documents.length);
}
I am working on a coldfusion website and trying to fix a bug. I've tried many things up until now, so here goes with StackOverflow.
The website in question needs the ability to both e-mail a pdf, and another function to print the pdf to the user for preview in the browser (in another window). I find that no matter what I do, these functions do not work concurrently.
Here is the code to do the e-mailing (coldfusion and JavaScript):
E-mail function and variables - wouldn't paste correctly in code format
The document is built using the following cfm file:
cfdocument file header - wouldn't paste correctly either
The code calls the same function (orderApprovalPdf.cfm) for both the print and e-mail abilities. Here is the javascript to call the printing:
form = document[this._PARENT.NAME+"MANAGEFORM"];
sel = ColdFusion.getElementValue(this._PARENT.NAME+"FORMSELECT");
switch(sel){
case 'APPROVAL' :
window.open('Pdf/orderApprovalPdf.cfm?PRODUCTORDERID=' + form.productOrderID.value);
break;
case 'SHIPDATECONFIRMATION' :
window.open('Pdf/vikingEstShipDatePdf.cfm?PRODUCTORDERID=' + form.productOrderID.value);
break;
case 'BOL' :
window.open('Pdf/billOfLadingPdf.cfm?PRODUCTORDERID=' + form.productOrderID.value);
break;
case 'INVOICE' :
window.open('Pdf/invoicePdf.cfm?INVOICEID=' + form.invoiceID.value);
break;
case 'INVOICECANADA' :
window.open('Pdf/invoicePdfCanada.cfm?INVOICEID=' + form.invoiceID.value);
break;
}
I tried all of the following:
A second .cfm file for the print functionality called from printForm – different cfm name, different cfm file directory, different path for the temporary file, and different temporary file name – e-mail would break unless the following in bold matched the original pdf function name despite being in the printForm function and not the emailForm function and appearing in no other places
case 'APPROVAL' :
window.open('Pdf/orderApprovalPdf.cfm?PRODUCTORDERID=' + form.productOrderID.value);
Alternatives to cfdocument property filename: saveasname, name (called from manageOrder.cfc as a variable such as #myPdf# when that was the name variable of the cfdocument – error on this saying myPdf variable did not exist no matter how I called it)
<cfdocument name=”myPdf” >
<cfmailparam file = “#GetTempDirectory()#Approval_#getApprovalInfoProcResult.ORDERNUMBER#.pdf" type=”application/pdf” content=”#myPdf” />
<cfcontent variable="#myPdf#" type="application/pdf" reset="Yes">
Tried adding cfcontent and cfheader tags in order to do the file saving (also to circumvent filename as an attribute) – did not make a difference, still couldn’t find the file when e-mail time came:
<cfheader name="Content-Disposition" value="attachment; filename=#GetTempDirectory()#Approval_#getApprovalInfoProcResult.ORDERNUMBER#.pdf" />
Moved the e-mail functionality from manageOrder.cfc to the orderApprovalPdf(cfm) file after the close of the <cfdocument> tag – but the program never hits this code
Any ideas? Maybe an alternative to cfdocument? I tried two separate cfm files and it looks like the window.open function does not allow this workaround.
Now an UltraEdit script is executed from the command line with:
uedit64.exe /s="J:\SkyDrive\work\ue-script\newFile.js"
Is it possible to pass parameters to UltraEdit script from command line? And how do I get them in the script?
Maybe like this:
uedit64.exe /s="J:\SkyDrive\work\ue-script\newFile.js" /pars="parameter1=value1,parameter2=value2"
And then get parameter1=value1 and parameter2=value2 in newFile.js.
UltraEdit scripts are executed usually from the command line to reformat one or more text files completely without user interaction and without depending on parameters. Or an UltraEdit script is started manually by a user from within UltraEdit without or with some minimal user interaction using getString and/or getValue. There are many scripting languages and script interpreters for doing something depending on parameters like VBScript, PowerShell, Perl, Python, etc.
It is not possible to specify additional custom parameters for an UltraEdit macro/script on the command line of UltraEdit. The command line arguments are interpreted by uedit64.exe or uedit32.exe and UltraEdit macros and scripts don't have access to arguments list of the executable.
I'm aware of three possibilities to pass strings (parameters) to an UltraEdit script from another process before starting UltraEdit and executing the script:
Via the clipboard, or
via a text file, or
by modifying the script before execution.
1. Pass parameters to an UltraEdit/UEStudio script via the clipboard
The first solution is easy to implement. But it has the big disadvantage that Windows clipboard content is modified on starting and no other process should copy something to the clipboard before the parameters and their values are read by the script. These disadvantages are very problematic if UltraEdit should be executed in the background for executing the script.
The following two commands must be executed on the command line or in a batch file:
echo parameter1=value1,parameter2=value2 | %SystemRoot%\System32\clip.exe
uedit64.exe /fni /s="J:\SkyDrive\work\ue-script\newFile.js"
clip.exe has been available since Windows Vista and Windows Server 2003. But there is no clip.exe on Windows XP. However, clip.exe from Windows Server 2003 can be also used on Windows XP.
It is highly recommended to use /fni (force new instance) on starting UltraEdit for executing a script from the command line when the configuration setting Allow multiple instances is not checked as by default. For an explanation why /fni should be used as the first parameter on the command line on running an UltraEdit macro/script from the command line, read topic Always get error message when running a macro/script via command line parameter (solved) in the UltraEdit forum.
An example script code for reading the parameters from clipboard is:
// Copy content of system (Windows/Mac/Linux) clipboard to a variable.
UltraEdit.selectClipboard(0);
var sParameterList = UltraEdit.clipboardContent;
// For safety check if the first parameter string begins with "parameter1".
if (sParameterList.indexOf("parameter1") == 0)
{
// Remove trailing withspaces from parameter list
var sParameterList = sParameterList.replace(/\s+$/,"");
// Split up the parameters list using comma as delimiter.
var asParameterList = sParameterList.split(',');
// For demonstration just open a message box listing the read
// parameters with their values without splitting them up further.
var sMessageText = "The parameter";
if (asParameterList.length > 1)
{
sMessageText += "s are:\n";
}
else
{
sMessageText += " is:\n";
}
for (var nParameter = 0; nParameter < asParameterList.length; nParameter++)
{
sMessageText += '\n "' + asParameterList[nParameter] + '"';
}
UltraEdit.messageBox(sMessageText,"List of parameters");
}
2. Pass parameters to UltraEdit/UEStudio script via a text file
In comparison to the first solution the clipboard is not modified by using this solution. However, it must be made sure that the following command lines are not executed at the same time by two processes.
> C:\Temp\ParameterList.tmp echo parameter1=value1,parameter2=value2
start "" /wait uedit64.exe /fni /s="J:\SkyDrive\work\ue-script\newFile.js"
del C:\Temp\ParameterList.tmp
The line output by command ECHO is redirected into text file C:\Temp\ParameterList.tmp, and then UltraEdit is started for running the script in a separate process and batch processing is halted until UltraEdit is exited. Finally, the temporary text file is deleted from the command line.
Example script code for reading the parameters from file with fixed name and path:
// Define the name of the file with the parameters with full path.
// The usage of environment variables in file name is not possible.
var sParameterListFile = "C:\\Temp\\ParameterList.tmp";
// Remember document index of active document which requires UltraEdit for
// Windows v16.00 or UEStudio v10.00. It would be possible to use code to
// get document index of active document on using an even older version of
// UltraEdit or UEStudio.
var nActiveDocIndex = UltraEdit.activeDocumentIdx;
// Open the parameter list file. This file should not be opened already
// before running this script. Otherwise additional code would be needed
// to search first in list of opened files for this file and read the
// parameters from already opened file and keep the file open instead
// of opening it and closing it after reading the first line.
UltraEdit.open(sParameterListFile);
// Test with a case-sensitive string comparison if the file could be really
// opened successfully in which case the parameter list file is the active
// file whose path property is the full name of the file with path.
if (UltraEdit.activeDocument.path == sParameterListFile)
{
// Define environment for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
// Read from the parameter list file just the first line without
// the line terminating character(s) and split up the parameters
// list using comma as delimiter before closing the file.
UltraEdit.activeDocument.startSelect();
UltraEdit.activeDocument.key("END");
UltraEdit.activeDocument.endSelect();
var asParameterList = UltraEdit.activeDocument.selection.split(',');
UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
// For safety check if the first parameter string begins with "parameter1".
if (asParameterList[0].indexOf("parameter1") == 0)
{
// For demonstration just open a message box listing the read
// parameters with their values without splitting them up further.
var sMessageText = "The parameter";
if (asParameterList.length > 1)
{
sMessageText += "s are:\n";
}
else
{
sMessageText += " is:\n";
}
for (var nParameter = 0; nParameter < asParameterList.length; nParameter++)
{
sMessageText += '\n"' + asParameterList[nParameter] + '"';
}
UltraEdit.messageBox(sMessageText,"List of parameters");
}
// Make the previously active document again the active
// document if there was any document opened before at all.
if (nActiveDocIndex >= 0)
{
UltraEdit.document[nActiveDocIndex].setActive();
}
}
For usage of a dynamic file name, the file name must be specified as the second parameter to open this file by UltraEdit before running the script and the script reads the parameters from the first opened file.
> "%TEMP%\Any File Name.txt" echo parameter1=value1,parameter2=value2
start "" /wait uedit64.exe /fni "%TEMP%\Any File Name.txt" /s="J:\SkyDrive\work\ue-script\newFile.js"
del "%TEMP%\Any File Name.txt"
The script code for this solution could be something like:
if (UltraEdit.document.length > 0) // Is any file opened?
{
// Define environment for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
// Move caret to top of first opened file which should
// be the file with the parameters for the script.
UltraEdit.document[0].top();
// Read from the parameter list file just the first line without the
// line terminating character(s) and split up the parameters list
// using comma as delimiter. The parameter list file remains opened.
UltraEdit.document[0].startSelect();
UltraEdit.document[0].key("END");
UltraEdit.document[0].endSelect();
var asParameterList = UltraEdit.document[0].selection.split(',');
// For safety check if the first parameter string begins with "parameter1".
if (asParameterList[0].indexOf("parameter1") == 0)
{
// For demonstration just open a message box listing the read
// parameters with their values without splitting them up further.
var sMessageText = "The parameter";
if (asParameterList.length > 1)
{
sMessageText += "s are:\n";
}
else
{
sMessageText += " is:\n";
}
for (var nParameter = 0; nParameter < asParameterList.length; nParameter++)
{
sMessageText += '\n"' + asParameterList[nParameter] + '"';
}
UltraEdit.messageBox(sMessageText,"List of parameters");
}
}
3. Modifying the script before execution
An UltraEdit script file is an ANSI text file and therefore it is possible to modify the script before execution.
echo var asParameterList = [ "value1", "value2" ];>"%TEMP%\ParameterList.tmp"
copy /B "%TEMP%\ParameterList.tmp" + "J:\SkyDrive\work\ue-script\newFile.js" "%TEMP%\TempScript.js" >nul
start "" /wait uedit64.exe /fni /s="%TEMP%\TempScript.js"
del "%TEMP%\ParameterList.tmp" "%TEMP%\TempScript.js"
The JavaScript code line which defines an initialized array of strings is first written into a temporary file. This temporary file is copied together with the script file to a new script in folder for temporary files. UltraEdit is executed using the temporary script file with the added parameter list array. Finally both temporary files are deleted from the command line.
An example script code which is extended dynamically with an additional line at the top to define the parameter strings:
// For demonstration just open a message box listing the parameter
// values as defined at top of the script from outside UltraEdit.
var sMessageText = "The parameter value";
if (asParameterList.length > 1)
{
sMessageText += "s are:\n";
}
else
{
sMessageText += " is:\n";
}
for (var nParameter = 0; nParameter < asParameterList.length; nParameter++)
{
sMessageText += '\n"' + asParameterList[nParameter] + '"';
}
UltraEdit.messageBox(sMessageText,"List of parameter values");
The advantage of this approach is that instead of an array of parameter strings it is also possible to define an array of integer numbers or floating point numbers. Or on the command line, multiple variables of different types are defined which are added to the temporary script file.
A last variant would be using // include parameters.js at top of the script file and the file parameters.js (with complete path or without path) is created dynamically on command line containing the lines to define the parameters in JavaScript language as JavaScript variables.
I have a html code that creates an input form on the browser and a javascript file that creates an array.The javascript program takes the input value and add it to the array and after display it on browser.
window.alert("Add some text")
var x;
var arr=["text1","text2"]
function myFunction() {
x=document.getElementById('input').value;
x=x.toLowerCase();
var y=arr.indexOf(x);
if (y!=-1) {
window.alert("You have added this text before");
} else {
arr.push(x);
document.getElementById('demo').innerHTML=arr ;
}
}
The problem is that when I exit the file(the web page displayed on my browser) I lose the inputs.Let's say that I add "text3" and the program display text3,when I exit the browser I lose the input "text3".
What can I do to save the inputs and display them even if I exit the program and I enter again?
Can I make two javascript file one with the array(like a database) and one that takes the input and save it in the other javascript file,and if so how do I make it?
As javascript is client side you will never be able to store permanent data as the script will be loaded (reset) after any refresh. Are you aware of the html5 localstorage concept? Saving data from js to the browsers storage space.
Edit:
Quick start on localstorage - http://www.w3schools.com/html/html5_webstorage.asp
I'm using iMacros firefox addon to automatize redundant tasks like downloading bills (pdf files) from a website to my local disk.
What I want is, if bill has been already downloaded, to not ask for download next time. Is there a way to know if a file already exists locally ?
My macros are integrated in a js script.
Thanks for your help.
Here is a simple workaround for that:
var ret = iimPlayCode("SET !FOLDER_DATASOURCE D:\\iMacros\\Downloads\\blablabla.pdf");
if (ret == 1) {
// file exists
} else {
// file doesn't exist
}
var ret = iimPlayCode("SET !FOLDER_DATASOURCE D:\\iMacros\\Downloads\\blablabla.pdf");
if (ret == 1) {
// file exists
} else {
// file doesn't exist
}
This code no work for me.
You can make use of SET !DATASOURCE command.
var retCode = iimPlayCode("SET !DATASOURCE C:\\my<SP>folder\\my<SP>file.csv");
if (retCode == 1)
{
alert("WARNING! - File already exists.");
//action you want to take
}
Replace all backslash ('\') with '\' and spaces with < SP > (without spaces) in the file path.
You can use FILEDELETE command to delete exisiting file if you want.
Note: Return code 1 means file exists. Not equal to 1 does not mean that file does not exis, there are many return codes possible like -910. See documentation for more detail. However in most cases, you just need to handle file exist case.