How to determine the current macro name

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to determine the current macro name

Stein Rørvik
Simple question:

Is there any way an ImageJ macro can determine its own filename?
That is, any way to read the name and file path of the currently loaded macro file?

Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to determine the current macro name

Volker Baecker
I don't think there is a simple way to do this.

File.directory
File.name

work for macro files as for other files, however you have to run the
command after opening the macro and before opening any other file.

getList("window.titles");

gives a list of all none image window titles including macros.

Maybe we can help more if you tell us why you need this.

Best regards,
Volker Baecker

Stein Rørvik:

> Simple question:
>
> Is there any way an ImageJ macro can determine its own filename?
> That is, any way to read the name and file path of the currently
> loaded macro file?
>
> Stein
>
> -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to determine the current macro name

Stein Rørvik
I need this because I maintain one macro that I put in different directories,
and the macro should behave differently depending on where its current location is.

I launch the macro from the command line on Windows.

I tried to read File.directory and File.name but they are both blank.

getList("window.titles") also does not work because there is no open macro window.

Is there some java property that I can read somewhere to determine the location and name of the macro that was launched from the command line?

Stein

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Volker Baecker
Sent: 10. desember 2015 13:44
To: [hidden email]
Subject: Re: How to determine the current macro name

I don't think there is a simple way to do this.

File.directory
File.name

work for macro files as for other files, however you have to run the command after opening the macro and before opening any other file.

getList("window.titles");

gives a list of all none image window titles including macros.

Maybe we can help more if you tell us why you need this.

Best regards,
Volker Baecker

Stein Rørvik:

> Simple question:
>
> Is there any way an ImageJ macro can determine its own filename?
> That is, any way to read the name and file path of the currently
> loaded macro file?
>
> Stein
>
> -- 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
Reply | Threaded
Open this post in threaded view
|

Re: How to determine the current macro name

Gabriel Landini
On Thursday 10 Dec 2015 14:10:14 you wrote:

> I need this because I maintain one macro that I put in different
> directories, and the macro should behave differently depending on where its
> current location is.
>
> I launch the macro from the command line on Windows.
>
> I tried to read File.directory and File.name but they are both blank.
>
> getList("window.titles") also does not work because there is no open macro
> window.
>
> Is there some java property that I can read somewhere to determine the
> location and name of the macro that was launched from the command line?

Hi
Not exactly what you asked and not sure it would work, but I wonder if you
could create a txt file in the folder where you put the macro. The file could
contain a value or string that tells the macro where it is running from.

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to determine the current macro name

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Stein Rørvik
> On Dec 9, 2015, at 8:46 AM, Stein Rørvik <[hidden email]> wrote:
>
> Simple question:
>
> Is there any way an ImageJ macro can determine its own filename?
> That is, any way to read the name and file path of the currently loaded macro file?

Upgrade to the latest ImageJ daily build (1.50f19) and you can use getInfo("macro.filepath”) to get file path and name of the currently loaded macro or script. In a plugin or script, use Macro_Runner.getFilePath().

-wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to determine the current macro name

Stein Rørvik
Thanks, just what I needed.

I tested this now on Windows:
It works for macros launched from the command line.
It works for macros installed under the plugins directory.
It works for macros launched by the runMacro() command.
It does not work however for macros installed "on-the-fly" by using menu Plugins - Macro - Install; it returns null.

Stein

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Rasband, Wayne (NIH/NIMH) [E]
Sent: 10. desember 2015 20:21
To: [hidden email]
Subject: Re: How to determine the current macro name

> On Dec 9, 2015, at 8:46 AM, Stein Rørvik <[hidden email]> wrote:
>
> Simple question:
>
> Is there any way an ImageJ macro can determine its own filename?
> That is, any way to read the name and file path of the currently loaded macro file?

Upgrade to the latest ImageJ daily build (1.50f19) and you can use getInfo("macro.filepath") to get file path and name of the currently loaded macro or script. In a plugin or script, use Macro_Runner.getFilePath().

-wayne

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

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to determine the current macro name

Michael Entrup
Hi,

this new function can be very useful for me. But the problem is, that I
always get the same, wrong path.

I'm using Fiji with IJ 1.50f24 on Windows 7. The minimal codes I run
from the script editor is listed at the end of this mail. The result of
both is:

     P:\PORTAB~1\Fiji.app\/macros/AutoRun/AutoRun_Scripts.ijm

Looks like Fiji is disturbing the correct use of the new function.

Best regards
Michael


Macro ("C:\temp\New_.ijm"):
     requires("1.50f");
     var name = getInfo("macro.filepath");
     IJ.log(name);


Jython ("C:\temp\New_.py"):
     from ij import IJ
     from ij.plugin import Macro_Runner
     name = Macro_Runner.getFilePath()
     IJ.log(name)



Am 11.12.2015 um 13:31 schrieb Stein Rørvik:

> Thanks, just what I needed.
>
> I tested this now on Windows:
> It works for macros launched from the command line.
> It works for macros installed under the plugins directory.
> It works for macros launched by the runMacro() command.
> It does not work however for macros installed "on-the-fly" by using menu Plugins - Macro - Install; it returns null.
>
> Stein
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Rasband, Wayne (NIH/NIMH) [E]
> Sent: 10. desember 2015 20:21
> To: [hidden email]
> Subject: Re: How to determine the current macro name
>
>> On Dec 9, 2015, at 8:46 AM, Stein Rørvik <[hidden email]> wrote:
>>
>> Simple question:
>>
>> Is there any way an ImageJ macro can determine its own filename?
>> That is, any way to read the name and file path of the currently loaded macro file?
>
> Upgrade to the latest ImageJ daily build (1.50f19) and you can use getInfo("macro.filepath") to get file path and name of the currently loaded macro or script. In a plugin or script, use Macro_Runner.getFilePath().
>
> -wayne
>
> --
> 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
Reply | Threaded
Open this post in threaded view
|

Re: How to determine the current macro name

Rasband, Wayne (NIH/NIMH) [E]
> On Dec 18, 2015, at 5:28 AM, Michael Entrup <[hidden email]> wrote:
>
> Hi,
>
> this new function can be very useful for me. But the problem is, that I always get the same, wrong path.
>
> I'm using Fiji with IJ 1.50f24 on Windows 7. The minimal codes I run from the script editor is listed at the end of this mail. The result of both is:
>
>    P:\PORTAB~1\Fiji.app\/macros/AutoRun/AutoRun_Scripts.ijm
>
> Looks like Fiji is disturbing the correct use of the new function.

You should report this bug using Fiji's Help>Report a Bug command so that it can be tracked and fixed.

-wayne


> Macro ("C:\temp\New_.ijm"):
>    requires("1.50f");
>    var name = getInfo("macro.filepath");
>    IJ.log(name);
>
>
> Jython ("C:\temp\New_.py"):
>    from ij import IJ
>    from ij.plugin import Macro_Runner
>    name = Macro_Runner.getFilePath()
>    IJ.log(name)
>
>
>
> Am 11.12.2015 um 13:31 schrieb Stein Rørvik:
>> Thanks, just what I needed.
>>
>> I tested this now on Windows:
>> It works for macros launched from the command line.
>> It works for macros installed under the plugins directory.
>> It works for macros launched by the runMacro() command.
>> It does not work however for macros installed "on-the-fly" by using menu Plugins - Macro - Install; it returns null.
>>
>> Stein
>>
>> -----Original Message-----
>> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Rasband, Wayne (NIH/NIMH) [E]
>> Sent: 10. desember 2015 20:21
>> To: [hidden email]
>> Subject: Re: How to determine the current macro name
>>
>>> On Dec 9, 2015, at 8:46 AM, Stein Rørvik <[hidden email]> wrote:
>>>
>>> Simple question:
>>>
>>> Is there any way an ImageJ macro can determine its own filename?
>>> That is, any way to read the name and file path of the currently loaded macro file?
>>
>> Upgrade to the latest ImageJ daily build (1.50f19) and you can use getInfo("macro.filepath") to get file path and name of the currently loaded macro or script. In a plugin or script, use Macro_Runner.getFilePath().
>>
>> -wayne

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