/* Offline_Macro_Help.txt Norbert Vischer, 14-jan-2011 Downloads "functions.html" plus those macro files that are referenced. This documentation about macro programming will then be locally accessible. In total, ~100 files are being downloaded. When finished, the local URL is shown in the Log window, and can be copied into a browser address field. In my tests, the download time was 1 minute. Tested on a Mac, the local URL looked like this: file:///Applications/ImageJ/macros/ImageJ-Help/developer/macro/functions.html Tested on Windows (via Parallels), the local URL looked like this: file://C:\Program Files\ImageJ\macros\ImageJ-Help\developer\macro\functions.html */ print("\\Clear"); selectWindow("Log"); localHelpDir = getDirectory("macros") + "ImageJ-Help/" ; //a) create local directories and save functions.html print("Creating directories..."); File.makeDirectory(localHelpDir); File.makeDirectory(localHelpDir + "developer"); File.makeDirectory(localHelpDir + "developer/macro"); htmlText= File.openUrlAsString("http://imagej.nih.gov/ij/developer/macro/functions.html"); localHtmPath = localHelpDir + "developer/macro/functions.html"; File.saveString(htmlText, localHtmPath); File.makeDirectory(localHelpDir + "macros"); File.makeDirectory(localHelpDir + "macros/examples"); File.makeDirectory(localHelpDir + "macros/tools"); File.makeDirectory(localHelpDir + "macros/toolsets"); //b) parse functions.html for linked files and download them print("Downloading ~100 files..."); start = 0; done = false; fileCount = 0; bytes = 0; while (!done){ start = indexOf(htmlText, "../../macros/", start); if (start < 0) done = true; else{ stop = indexOf(htmlText, "\"", start); remainingPath = substring(htmlText, start + lengthOf("../../macros/"), stop); start = stop; src = "http://imagej.nih.gov/ij/macros/" + remainingPath; fileContents = File.openUrlAsString(src); dest = localHelpDir + "macros/" + remainingPath; bytes += lengthOf(fileContents); File.saveString(fileContents, dest); fileCount++; showStatus("" + fileCount + ": " + remainingPath); } } print("Number downloaded files = " + fileCount); print("Number of characters =", round(bytes/1024) + " K"); print("Local URL:"); print("file://" + localHtmPath);