Skip to content

Instantly share code, notes, and snippets.

@mutterer
Created June 17, 2020 09:51
Show Gist options
  • Save mutterer/4dfbcdb11704c940f0ec1e453cd177b2 to your computer and use it in GitHub Desktop.
Save mutterer/4dfbcdb11704c940f0ec1e453cd177b2 to your computer and use it in GitHub Desktop.
a basic ImageJ macro that will prompt you for update at given intervals.
/*
// run just those 3 lines to reset update preferences
call( 'ij.Prefs.set', 'update.freq', 1 );
call( 'ij.Prefs.set', 'update.mode', "stable release" );
call( 'ij.Prefs.set', 'update.last', 0 );
*/
lastUpdate = parseInt( call( 'ij.Prefs.get', 'update.last', 0 ) );
updateFreq = parseInt( call( 'ij.Prefs.get', 'update.freq', 1 ) );
updateMode = call( 'ij.Prefs.get', 'update.mode', "stable release" );
elapsedTime = floor( getTime( )/( 1000 * 60 ) )- lastUpdate;
days = parseFloat(d2s( elapsedTime /( 60 * 24 ), 2 ));
if( days > updateFreq ) {
s = File.openUrlAsString( "http://wsr.imagej.net/jars/list.txt" );
if( s.indexOf( "Error" )>- 1 ) {
showStatus( "no network" );
exit( );
} else {
s = split( s );
}
Dialog.create( "ImageJ1 Auto Updater" );
Dialog.addMessage( "Available stable version: " + s [ 0 ] );
Dialog.addMessage( "You have ImageJ version: " + getVersion( ) );
Dialog.addMessage( "Full version number: " + IJ.getFullVersion( ) );
Dialog.addMessage( "Last update was " + days + " days ago." );
Dialog.addNumber( "Prefered update interval", updateFreq, 0, 5, "days" );
Dialog.addChoice( "Update mode", newArray( "stable release", "daily build" ), updateMode );
Dialog.addCheckbox( "Do update", false );
Dialog.show( );
updateFreq = Dialog.getNumber( );
updateMode = Dialog.getChoice( );
doUpdate = Dialog.getCheckbox( );
call( 'ij.Prefs.set', 'update.freq', updateFreq );
call( 'ij.Prefs.set', 'update.mode', updateMode );
if( doUpdate == true ) {
setTool( 'angle' );
call( 'ij.Prefs.set', 'update.last', floor( getTime( )/( 1000 * 60 ) ) );
if( updateMode.startsWith( "stable" ) ) updateMode = s [ 0 ];
run( "Update ImageJ...", "upgrade=[" + updateMode + "]" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment