As this is the only JAVA thread, I thought I'd add a couple of javascript utility functions that use Java to access local files.
Note: These functions should include exception handling. At present, their flow only includes the "happy path".
To load a fileCode: Select all
//Load a file into a string
// filePath example: "C:\\temp\\myFile.txt"
function loadFile(filePath){
// Load the file
var stringBuilder = new java.lang.StringBuilder();
var bufferedReader = new java.io.BufferedReader(new java.io.FileReader(filePath) );
var line = null;
while( ( line = bufferedReader.readLine()) != null)
stringBuilder.append(line + java.lang.System.getProperty("line.separator") );
bufferedReader.close();
return stringBuilder.toString();
}
To load configuration settings
Code: Select all
//Load a properties file (for having a config file for your scripts, for example)
//fileName example: "C:\\config\\MyMacro.properties"
function loadProperties(fileName) {
var returnValue = new java.util.Properties();
var properties = new java.io.FileInputStream(fileName);
returnValue.load(properties);
properties.close();
return returnValue;
}
Example Usage (C:\config\MyMacro.properties)
Properties file
timeout=20
image.folder=C:\screen<SP>shots
image.type=PNG
data.source=C:\Data.csv
data.columns=20
url=
http://www.google.com
macro.name=MyMacro
Javascript
...
Code: Select all
var properties = loadProperties("C:\\config\\MyMacro.properties");
iimSet("timeout", properties.getProperty("timeout") );
iimSet("imageFolder", properties.getProperty("image.folder") );
iimSet("imageType", properties.getProperty("image.type") );
iimSet("dataSource", properties.getProperty("data.source") );
iimSet("dataColumns", properties.getProperty("data.columns") );
iimSet("url", properties.getProperty("url") );
iimPlay( properties.getProperty("macro.name") );
...
iMacro script (MyMacro.iim)
...
Code: Select all
SET !TIMEOUT {{timeout}}
SET !DATASOURCE {{dataSource}}
SET !DATASOURCE_COLUMNS {{dataColumns}}
URL GOTO={{url}}
SAVEAS TYPE={{imageType}} FOLDER={{imageFolder}} FILE=*
...
iMacros for Firefox supports JavaScript Macros (Scripting)
JavaScript supports Java via LiveConnect
Therefore: You can write powerful macros with iMacros for Firefox. Have a look at
this one
Post feature requests
here. Maybe one day, they'll pin it?