isMacintosh boolean in a macro?

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

isMacintosh boolean in a macro?

Bill Mohler
I've just come across the mismatch in path punctuation in macros
between Mac and Windows:  "/" vs "\\" to demarcate directory levels
when I record a save command in the recorder.

I found an isMacintosh boolean in some of the ij. code.  But I didn't
find an obvious command in the macro language command list that would
let my macro detect the platform it's running on.

Is there an easy way to detect the OS from in a macro, so I can
substitute in the correct punctuation?  I assume that ImageJ is aware
of its environment, but how do I ask it?

Thanks,
Bill
Reply | Threaded
Open this post in threaded view
|

Re: isMacintosh boolean in a macro?

Gabriel Landini
On Saturday 11 October 2008, Bill Mohler wrote:
> Is there an easy way to detect the OS from in a macro, so I can
> substitute in the correct punctuation?  I assume that ImageJ is aware
> of its environment, but how do I ask it?



Yes, search for "os" in this page:
http://rsbweb.nih.gov/ij/developer/macro/functions.html

you will find this:

getInfo(key)
Returns the Java property associated with the specified key
(e.g., "java.version", "os.name", "user.home", "user.dir", etc.). Returns an
empty string if there is no value associated with the key. See also:
getList("java.properties"). Requires 1.38m.

which is what you want, I think.
I hope it helps
Cheers

G.
Reply | Threaded
Open this post in threaded view
|

Re: isMacintosh boolean in a macro?

Bill Mohler
Thanks.
I  had  tried  this, and was lost in all the hits on macrOS.

>On Saturday 11 October 2008, Bill Mohler wrote:
>>  Is there an easy way to detect the OS from in a macro, so I can
>>  substitute in the correct punctuation?  I assume that ImageJ is aware
>>  of its environment, but how do I ask it?
>
>
>
>Yes, search for "os" in this page:
>http://rsbweb.nih.gov/ij/developer/macro/functions.html
>
>you will find this:
>
>getInfo(key)
>Returns the Java property associated with the specified key
>(e.g., "java.version", "os.name", "user.home", "user.dir", etc.). Returns an
>empty string if there is no value associated with the key. See also:
>getList("java.properties"). Requires 1.38m.
>
>which is what you want, I think.
>I hope it helps
>Cheers
>
>G.
Reply | Threaded
Open this post in threaded view
|

Re: isMacintosh boolean in a macro?

Wayne Rasband
In reply to this post by Bill Mohler
On Oct 11, 2008, at 7:01 AM, Bill Mohler wrote:

> I've just come across the mismatch in path punctuation in macros  
> between Mac and Windows:  "/" vs "\\" to demarcate directory levels  
> when I record a save command in the recorder.
>
> I found an isMacintosh boolean in some of the ij. code.  But I  
> didn't find an obvious command in the macro language command list  
> that would let my macro detect the platform it's running on.
>
> Is there an easy way to detect the OS from in a macro, so I can  
> substitute in the correct punctuation?  I assume that ImageJ is  
> aware of its environment, but how do I ask it?

Use the File.separator() function to get the file path separator,  
which is "/" on Macs and Linux and "\\" on Windows. Note that the  
getDirectory() macro function returns a file path that ends with a  
path separator.

Use

    if (getInfo("os.name")=="Mac OS X")
       print("This is a Mac")

or

    if (call("ij.IJ.isMacintosh")=="true")
       print("This is a Mac")

to test to see if you are running on a Macintosh.

-wayne