isOpen functionality

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

isOpen functionality

bds81175
I have a set of ImageJ macros that I want to have read a .txt file and process based on the files contents.  Unfortunately, I want to have multiple PC's working with the same file and I don't want them tripping over each other when the file gets opened and read by one and another tries to do the same.  I see the isOpen command but for the life of me I can't get it to actually return a TRUE flag.  Is there a trick to this?  What's the best way to keep the macros running while using the same file?
Reply | Threaded
Open this post in threaded view
|

Re: isOpen functionality

Nathaniel Ryckman
isOpen("Title")
Returns true if the window with the specified title is open.

http://rsbweb.nih.gov/ij/developer/macro/functions.html

I recommend creating a plugin. The Macro language is run from a Java program. The Macro language doesn't offer as many tools as Java and can be buggy. The Macro language is meant for creating simple programs that will help a user avoid using the menu manually. It's apparently not meant for full-fledged programs.

A plugin, on the other hand, is made from pure Java. It runs from a JVM (Java bytecode); thus, you have almost unlimited control if you make a plugin rather than a Macro.

To summarize:

Assembly->JVM->Java->Macro Language

bds81175 wrote
I have a set of ImageJ macros that I want to have read a .txt file and process based on the files contents.  Unfortunately, I want to have multiple PC's working with the same file and I don't want them tripping over each other when the file gets opened and read by one and another tries to do the same.  I see the isOpen command but for the life of me I can't get it to actually return a TRUE flag.  Is there a trick to this?  What's the best way to keep the macros running while using the same file?
Reply | Threaded
Open this post in threaded view
|

Re: isOpen functionality

Nathaniel Ryckman
In reply to this post by bds81175
Actually, I have an idea. If you absolutely do not want to create a plugin, you can make pseudo-permissions.

Create a .txt file called "permissions.txt" in the folder with the file with the data. Have 1 line in the .txt file with the letter "t" or "f". From the macro, read the first line of the text file. If the file says "t", then change it to "f", else do nothing. After changing it to "f", have your program edit the shared data file. Finally, change the permission.txt file back from "f" to "t".

The only problem is there is a 1 in a million chance that while your program is changing the permission.txt file from "t" to "f", another program will read the .txt file as "t" and try to do the same thing, but, really, this is as good as you are going to get from a macro program.

You can read about the details behind this concept here:

http://en.wikipedia.org/wiki/File_locking