If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[Minor] macOS Application Bundle CLI Support

macOS application bundles are meant to be usable with both a GUI and CLI, if they are available.

The GUI, of course, is launched by opening the (ApplicationName).app bundle in Finder, or using the ďopenĒ command in a shell. CLIs are usually accessed by running the raw binary at (ApplicationName).app/Contents/(BinaryName, which might be different).

In the case of KoLmafia, that binary is JavaApplicationStub. I can launch it from the command line just fine, and I can see System.out and System.err normally. Unfortunately, unlike the JAR build, it just launches the GUI instead of accepting arguments.

I understand this is a very small issue, since users can just keep two copies of KoLmafia around, or just use a JAR for everything. But it may not be that hard to implement, and it would be very convenient. Iím not too familiar with Ant, so it might even be a matter of changing a setting somewhere.

But it may not be that hard to implement, and it would be very convenient. I’m not too familiar with Ant, so it might even be a matter of changing a setting somewhere.

Originally Posted by Saklad5

All the devs (and many other people as well) can build a jar. But the Mac specific "packaging" done for "official releases" (dmg file) can only be done by a couple of people. OS specific code tends to be avoided unless it makes life easier for a dev with that OS or the lack of such code breaks KoLmafia functionality.

With that background, you might consider telling us what has to change to give you what you want. Does the dmg file do what you want? If so then this is really a request that the DailyBuilds also include dmg files as well as jars. If I have all the Java class files, can you tell me the commands to package them to give you what you want? If so then it might be reasonably simple to add another target to the build file. Does the source code need to be modified to introduce a new class? If so, what is the class and what should it do?

I'm also not sure why "keeping the jar" around is an issue. What are you downloading or building, if not the jar? How do you transform it to get what you want?

I build the .app bundle from the source code using Apache Ant with the jarbundler instruction that is included in the build file. That already uses OS-specific code, as does the exe for Windows.

If I knew how to do this myself, I would do so and submit a patch. I don’t, unfortunately, so I can only ask if anyone else does. As I said in the first post of this thread, running the binary inside the application bundle on the command line launches the GUI while showing console output. I understand that the JAR will actually allow user input on the command line if run that way. I want the binary to act the same.

The DMG is just a disk image that contains a .app bundle, by the way. It isn’t a distinct thing.

It is not necessarily you. My knowledge of Mac specific tools and conventions and vocabulary is non-existent.

Uncle Google suggests that the behavior you want is controlled by JavaApplicationStub which is provided by the (development) build environment. Uncle Google also suggests that "default" JavaApplicationStub files are Java and OS specific. I'm not going to go down that rabbit hole with only Windows and Linux to play with.

It would be helpful if a Mac dev would execute the jarbundler task and run the result. If it behaves as you describe (and don't want) then the task probably needs to be tweaked, possibly by using a mafia provided JavaApplicationStub equivalent. If it behaves differently then the solution lies in the differences between the two Mac environments.

All that said, I think your only solution is going to be to keep the jar around unless someone else gets interested.

…I’m an idiot. I just realized some of the guides had the --CLI flag after the JAR. Sure enough, adding that flag after the application binary let me access the KoLmafia CLI. In other words, it already works as I want: the only issue is that all the guides incorrectly say that only the JAR can do that.

I’m willing to bet the output-only state I described also occurs if you run the JAR from the command line without that flag.