. There is a small API to communicate with PhotoGrok. Scripts are saved with settings. The following functions can be called:
New functions in PhotoGrok 2.41:
- getMap() : Returns a Java HashMap for persisting information. The "Clear Map" button removes all entries from the map.
- showMessage(msg) : Displays a message dialog to the user. Typically called from done() callback function.
- request(label) : Returns a value entered by the user. "label" is displayed above the text input on the dialog.
- dec(shutterspeed) : Takes an ExifTool ShutterSpeed value and converts it to a decimal number.
- done() : Callback function called when the tree or catalog build is complete. Useful for displaying information. Use 'background' function (below) if you need to execute a long-running task.
New functions in PhotoGrok 2.42:
- buildTree(fromCatalog, doneFunc) : Runs a tree build. Boolean "fromCatalog" determines whether to build from catalog or real time. "doneFunc" is a function to run when build is complete. This function does nothing if called during another tree or catalog build.
- getNodes() : Returns an array of all nodes in the tree. Each node object has a "name" and "dir" property.
- selectNode(node) : Expands the tree and selects the "node". See getNodes() for details on obtaining node objects
- setExtensions(ext) : Sets the extensions in preferences. "ext" is a comma-delimited string of file extensions.
- getTagValue(tag) : Returns the value for "tag" string from the list of exif data on the screen.
- getExifData(dir, file) : Returns a complete list of exif data including custom tags for the given directory and file. Calls ExifTool so can be expensive.
- background(bgFunc, doneFunc) : Runs "bgFunc" function in a background thread (while blocking user input). "doneFunc" executes when background thread finishes (can be null).
- setPainter(painterFunc) : The painterFunc function (details below) allows drawing on the main PhotoGrok image panel. Can be used to implement histograms, etc.
- onBuildTree(fromCatalog) : Callback function fired when a tree build is executed. "fromCatalog" will be true if tree built from catalog.
- onBuildCatalog() : Callback function fired when a catalog build is executed.
- onLoadSettings() : Called when a new setting preset is loaded. Call buildTree function to create auto-executing preset.
New functions in PhotoGrok 2.43:
- setThumbnailPainter(painterFunc) : Sets a painter function for thumbnails and the popup preview.
- addMenuCommand(label, function) : Add a command to the popup menu for an image/tree node. The passed in function will execute if the menu item is selected.
- execExifTool(array) : Pass in an array of strings containing Exiftool command line options. Returns output from ExifTool as an array of strings.
- execCommand(dir, cmdarray) : Runs a external program. String dir is the directory to run in (can be null) and cmdarray is a string array containing the command and arguments to run. Since 2.45 returns object with returnCode and response. returnCode is an int and response is an array of strings containing output of command.
- xzCompress(dir, filename) : Compress a file. The output file is saved to the same directory as the original with an .xz extension. Returns true if successful.
- xzDecompress(dir, filename) : Decompress an .xz file. Output file is saved to same directory minus the .xz extension. Returns false if action fails, the file doesn't end in .xz or the decompressed file already exists.
- setTags(tags) : Sets the tags used for building a dynamic tree. Argument is a comma-delimited list of ExifTool/PhotoGrok tags.
- copyTree(node, string) : Copy a tree structure to destination directory (similar to popup menu's "copy tree"). Node is a treenode (see getNodes function). String is destination directory. Function does nothing if tree or catalog build is running.
- importCatalog() : Imports files into catalog based on current settings. Use setExtensions and setScanDirs functions to change which dirs/files are scanned. Does nothing if tree build or catalog import already running.
- refreshFile(dir, file) : Refreshes/adds a file's data into the current catalog. If file doesn't exist in filesystem the file's data is removed from the catalog. Returns true if successful. Does nothing if tree build or catalog import currently running.
- setStatusText(txt, boolean) : Set the status bar message to txt. Boolean flag to show spinning busy icon. Pass null to clear status message.
Global variables are cleared between each execution. Use getMap() to persist data if necessary. The main script is evaluated when the script window is closed, when a new setting is loaded and when a tree or catalog is built manually (not through automated script functions).
Scripts can call the full Java API (see Java's Rhino and/or Nashorn documentation).