Console Snippets

Revision as of 27 April 2022 22:28 by RobM (Comments | Contribs)

These are small blocks of code that users can enter in jAlbum’s system console (press F7 or use Menu/Tools/System console to open the console’s window. Paste the code into the top section of the window and then press the ‘Execute’ button. All of the code snippets below are Beanshell unless other wise stated. If another language is used, like JavaScript, then change the scripting language as required. Read more on the system console here

There is also a blog post by David called automate it that provides additional examples and explanations.

Code Snippets

Using Groovy scrtipting exclude all images rated less than 3 stars.

currentFolder.descendants.stream().filter(ao -> ao.rating < 3).forEach(ao -> ao.included = false)

To check if your computer’s screen is a ‘HI-DPI’ (High Definition) display or not, use this code

GraphicsUtilities.getScale(window.getGraphicsConfiguration().getDevice());

If the resulting value is greater than 1, then it is a HI-DPI screen.



A way of quickly making an album out of specific flagged images only, for example Red flagged images:

sync = new AlbumSynchronizer(engine);
currentFolder.getDescendants(IncludeOption.EXCLUDED).stream().forEach(ao -> {
  ao.included = ao.folder || ao.flag == Flag.Select;
  if (!ao.included) sync.delete(ao);
})

It will also delete the corresponding excluded images from the album. Values for ‘Flag’ are

None, Red/Select, Yellow/Second, Blue/Review and Green/Approved



If you are having a problem processing an album but don’t get an obvious error message, maybe jAlbum just slows right down, then use:

JAlbum.dumpThreads();

This will create a ‘thread-dump.txt’ file in jAlbum’s configuration folder (use SHIFT + CMD/CNTRL + C to one the folder in your OS).



Here's a quick way to change a published album’s protocol from http to https.

1) Open the relevant project

2) Open the system console (F7) and execute the following code in the upper panel:

props = rootFolder.getProperties();
albumURL = props.get("albumURL");
props.put("albumURL", albumURL.replace("http:", "https:"));
props.save();



Change all instances of a keyword into another Make sure the 'Scripting language' is set to 'Groovy (Groovy scripting engine). In the code below replace the search and replace strings (Test and Tested) with the keyword to be replaced and the replacement. Then click on the 'Execute' button to run the code.

Work.on(rootFolder.descendants)
.forEach(ao) -> {
	Set keywords = ao.keywordSet
	if (keywords.remove("Test")) {
		keywords.add("Tested")
		ao.keywords = StringUtil.setToString(keywords)
	}
}



Show all of the GUI settings and values, such as colours, font sizes etc. Handy for checking/altering jAlbum's own skin/theme colours.

import java.util.Set;
import java.util.Map.Entry;
 
 entries =  UIManager.getLookAndFeelDefaults().entrySet();
    for (Entry entry : entries)
    {
      System.out.print(entry.getKey() + " = ");
      System.out.print(entry.getValue() + "\n");
    }



List all the names of jAlbum panels and controls. This code requires Groovy script be selected in the system console.

window.binder.walkComponents((name, comp) -> {
	if (name.contains("Panel")) {
		println name
	}
})



To correct image files misnamed as HEIC instead of JPG (Often the result of downloading HEIC images from Google Photos) follow the instructions below:

You will first need to select the files you want renaming in jAlbum's explore view, then paste the following code into the top half of the system console (F7 to open it). Select 'BeanShell' as the scripting language and then press the 'Evaluate' button.

AlbumObject[] selAOs = JAlbumContext.getInstance().getExplorer().explorer.getSelectedAlbumObjects();
AlbumObject thisFolder = JAlbumContext.getInstance().getExplorer().getCurrentFolder();
for (AlbumObject ao : selAOs) {
	if(ao.getName().endsWith(".heic")) {
		ao.moveTo(thisFolder, ao.getName().replaceAll("heic","jpg"));
	}
	else if(ao.getName().endsWith(".HEIC")) {
		ao.moveTo(thisFolder, ao.getName().replaceAll("HEIC","JPG"));	
	}
}
window.albumExplorer.refreshAction.actionPerformed(null);