Feature - Implemented [Minor] macOS Application Bundle CLI Support

Saklad5

Member
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.
 
Can't you just run the jar from the terminal?

Something like: java -jar -Djava.awt.headless=true -XX:+PrintGCDetails Desktop/KoLmafia-18559M.jar
 

Saklad5

Member
As I said, it’s possible to just keep the JAR around as well. There’s a reason I denoted this as minor. This is a nice-to-have, nothing more.
 
As I said, it’s possible to just keep the JAR around as well. There’s a reason I denoted this as minor. This is a nice-to-have, nothing more.

Ah, I see where I was confused. I only use the JAR (whether I want the GUI or not) but apparently you can get it in different packaging.
 

fronobulax

Developer
Staff member
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.

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?
 

Saklad5

Member
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.

I’m sorry if this isn’t clear, I’m not sure how to better explain it.
 

fronobulax

Developer
Staff member
I’m sorry if this isn’t clear, I’m not sure how to better explain it.

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.
 

Saklad5

Member
…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.
 

Saklad5

Member
For future reference, macOS users can access the CLI by running:

{Path of KoLmafia application bundle}/Contents/MacOS/JavaApplicationStub --CLI

in a shell of your choice.
 

fronobulax

Developer
Staff member
Glad we all learned something.

I did make an error above. KoLmafia does have a version of JavaApplicationStub that is managed and provided by KoLmafia.
 
Top