Login  Register

Re: Easy way for modifying Shortcuts

Posted by Michael Schmid on Nov 21, 2013; 3:55pm
URL: http://imagej.273.s1.nabble.com/Easy-way-for-modifying-Shortcuts-tp5005571p5005633.html

Hi Philippe,

the extra space for 'Fn' shortcut keys is probably meant to get the F-keys at the top in the sorted list (it's in ij.plugin.CommandLister.java, line 57).  When doing a hack like the one we are discussing here, one may easily run into such problems; that's why I thought the other method with macro sets would be nicer...

For adding a shortcut, you have to run("Refresh Menus") after deleting the old one and *before* adding the new one.

And you might want a run("Close") after list = getInfo("window.contents"); otherwise the 'Keyboard Shortcuts' window will stay on the screen forever.

Michael   (not Peter ;-)
________________________________________________________________
On Nov 21, 2013, at 15:17, Philippe CARL wrote:

> Dear Peter,
> I thank you very much for your help and looking at the code you sent me in
> your previous mail, it is quite obvious that your level in programming is
> quite far away from mine.
> Thus using your excellent advices, I have tried to use the following code:
>
> run("List Shortcuts...");
> selectWindow("Keyboard Shortcuts");
> list = getInfo("window.contents");
> lines = split(list,'\n');
> List.clear();
> for (i=0; i<lines.length; i++)
> {
>  items = split(lines[i],'\t');
>  List.set(items[0], items[1]);
> }
> run("Remove...", "command=["+List.get(' F2')+"]");
> run("Create Shortcut... ", "command=[Open Recent File 1] shortcut=F2");
> run("Refresh Menus");
>
> First it took me quite some time to understand that in other to use the key
> associated to the F2 key I needed to put a space in front of F2, i.e. use '
> F2' instead of 'F2'. Is there a reason for this?
> Then the code pasted higher is correctly erasing the Shortcut associated to
> the F2 key, nevertheless Fiji really needs to be closed in order be able to
> attribute a new Shortcut to the same key.
> Why is this? Am I still doing something wrong?
> I thank you very much in advance for your help.
> Best regards,
> Philippe
>
> -----Message d'origine-----
> De : ImageJ Interest Group [mailto:[hidden email]] De la part de
> Michael Schmid
> Envoyé : mardi 19 novembre 2013 17:49
> À : [hidden email]
> Objet : Re: Easy way for modifying Shortcuts
>
> Hi Philippe,
>
> concerning the first solution, you can, e.g., have the following in
> StartupMacros.txt:
>
> // Preprocessing shortcut key definitions macro 'Despeckle [F1]' {
>  run("Despeckle", "stack");
> }
> macro 'Remove standard outliers [F2]' {
>  run("Remove Outliers...", "radius=2 threshold=50 which=Bright"); } macro
> 'Switch to Analysis Macros [F7]' {
>  run("Install...",
> "install="+getDirectory('macros')+"myAnalysisMacroSet.txt");
> }
>
> And in ImageJ/macros/myAnalysisMacroSet.txt you might have have
>
> // Image analysis shortcut definitions
> macro 'Analyze Big Nonspherical Particles [F1]' {
>  run("Analyze Particles...", "size=999-Infinity circularity=0.4-1.00
> show=Nothing display"); } macro 'Analyze Small Round Particles [F2]' {
>  run("Analyze Particles...", "size=0-9999 circularity=0.0-0.6 show=Nothing
> display"); } macro 'Analyze Particles User-Defined [F3]' {
>  run("Analyze Particles..."); //'Analyze Particles' dialog will be shown.
> }
> macro 'Switch Back to Preprocessing Macros [F8]' {
>  run("Install...", "install="+getDirectory('macros')+"StartupMacros.txt");
> }
>
> ---
> For retrieving the shortcuts list and extracting shortcuts from it:
>
> run("List Shortcuts...");
> selectWindow("Keyboard Shortcuts");
> list = getInfo("window.contents");
> lines = split(list,'\n');
> List.clear();
> for (i=0; i<lines.length; i++) {
>  items = split(lines[i],'\t');
>  List.set(items[0], items[1]);
> }
> print (List.get('S')); //prints the command for shortcut 'S'
>
> This way of programming depends much more on details of the implementation,
> e.g., it will fail if some future version of ImageJ should happen to have a
> different window title for the list of shortcuts...
>
>
> Michael
> ________________________________________________________________
> On Nov 19, 2013, at 16:05, Philippe CARL wrote:
>
>> Dear Michael,
>> I thank you very much for your answer, but I'm afraid that I don't
>> really understand how to implement your first solution.
>> And for your second solution, how is it possible to retrieve the 'List
>> Shortcuts' table?
>> I thank you very much in advance for your answer.
>> Best regards,
>> Philippe
>>
>> -----Message d'origine-----
>> De : ImageJ Interest Group [mailto:[hidden email]] De la part de
>> Michael Schmid Envoyé : vendredi 15 novembre 2013 15:59 À :
>> [hidden email] Objet : Re: Easy way for modifying Shortcuts
>>
>> Hi Philippe,
>>
>> you can define shortcuts for macros.  Have the macro run the command
>> you want.  These override the standard ImageJ macros (but they don't
>> appear in the menus).
>>
>> If you have macro sets, you can switch between them by installing one
>> macro set or another, and so you get different sets of shortcuts.
>>
>> You can even have one macro set install another one by something like  
>> run("Install...",
>> "install="+getDirectory('macros')+"myNextMacroSet.txt");
>>
>> --
>>
>> You can also do the 'standard' ImageJ shortcut removal and adding
>> commands with macros.
>> 'Record Macros' tells you how:
>>
>> run("Create Shortcut... ", "command=[My Command] shortcut=0");  
>> run("Remove...", "command=[*My Command]");  run("Refresh Menus");
>> //you don't need to restart ImageJ, even if it says so.
>>
>> The disadvantage of the latter method is that you need to analyze the
>> 'List Shortcuts' table to know which command currently uses a shortcut
>> that you want to redefine.
>> Also, "Refresh Menus" loses the list of open windows in the 'Window' menu.
>>
>>
>> Michael
>> ________________________________________________________________
>> On Nov 15, 2013, at 15:38, Philippe CARL wrote:
>>
>>> Dear all,
>>>
>>> I’m playing a lot with Shortcuts when I analyze some pictures since
>>> they give the possibility to seriously accelerate the workflow.
>>>
>>> But depending on the given type of analysis to perform, the use of
>>> different lists of Shortcuts would be interesting.
>>>
>>> And it is quite heavy to each time first "Remove" old Shortcuts and
>>> then "Create" new ones when changing from a given analysis to another
> one.
>>>
>>> Thus how is it possible to more easily access and modify the list of
>>> Shortcuts by using for example a text editor software?
>>>
>>> I thank you very much in advance for your help and answer.
>>>
>>> Best regards,
>>>
>>> Philippe
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html