-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathBeanShell06.bsh
39 lines (33 loc) · 1.83 KB
/
BeanShell06.bsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* BeanShell06.bsh
* IJ BAR: https://github.com/tferr/Scripts#scripts
* *************************************************
* 6. Further examples
* *************************************************
*/
// Several BAR scripts are actually written in BeanShell. E.g., have a look
// the scripts in the "BAR> Analysis>" Menu (Remember the shift-click trick?).
//
// Alternatively, you can search for BeanShell files by searching your
// "My Routines" (itself a BeanShell script) and search for ".bsh".
// (If currently your My_Routines is empty, you can populate it by running
// "BAR> Utilities> New Snippet", or "Install Multi-language libs...").
//
// We could use the Macro Recorder to generate the required code for this
// rather simple task. However, we'll take advantage of the fact that, when
// search field in the "Search Routines" prompt is empty, the query becomes
// the contents of clipboard.
//
// So, for the purpose of pure scripting fun we'll place ".bsh" in the system
// clipboard before calling "BAR>My Routines>Search Routines...":
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import ij.IJ; // http://javadoc.imagej.net/ImageJ1/ij/IJ.html
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // http://javadoc.imagej.net/Java7/index.html?java/awt/Toolkit.html
selection = new StringSelection(".bsh"); // http://javadoc.imagej.net/Java7/index.html?java/awt/datatransfer/StringSelection.html
clipboard.setContents(selection, selection);
// Now we can simply call the script as if we were running it from the BAR>
// menu (BTW, this works flawlessly in IJ1 because labels of menu items
// across all menus are unique):
IJ.run("Search Routines...", "searchstring= searchcontents=false casesensitive=false uiservice=[org.scijava.ui.DefaultUIService [priority = 0.0]]");
// Now, go ahead and press <<Run>>!