OSX Xboard 4.7.2 .app

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: OSX Xboard 4.7.2 .app

Post by hgm »

No need to despair yet: by further reading of the man page for open I found the following:
open(1) wrote:--args
All remaining arguments are passed to the opened application in the argv parameter to main().
These arguments are not opened or interpreted by the open tool.
So it seems that

Code: Select all

open -n -a xboard-bin --args -ncp
should do it. (I think quotes around "xboard-bin" would be redundant, as the name doesn't contain spaces. You could add " around it, though.) I don't know how you pass arguments to the launch script to xboard-bin now, but I guess you could just prefix xboard-bin with "open -n -a " and slip a " --args" directly after it in the launch script.

This should then work with the old XBoard, that ignores the OpenFile signals. (You can comment out the g_signal_connect() line to get that back; the presence of StartNewXBoard() would not have any effect without that; it would just never be invoked, even if an OpenFile signal would be received.)
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: OSX Xboard 4.7.2 .app

Post by hgm »

Off-topic:

note I pushed a new version of XBoard-compatible Bonanza sources to hgm.nubati.net (test branch). There was a problem with switching to force mode after setboard.
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Ooh nice nice all around! nice avatar! great news about bonanza. I can't believe I missed that argument last night!

I fear I couldn't put open in the launch script. Part of what it does is set the gtk environment and passes it to xboard with the '$EXEC xboard-bin' command. open doesn't take into account everything set before it. :(
Besides, we need the signal else the OS would be opening xboard without the PGN File argument, and we would just be opening multiple instances of clean xboard.

But we can always put it back into the code like we were doing.

And this works!...mostly. When clicking on a pgn file, the first instance always doesn't load the pgn file, every instance after that does. I have tried going back to the old suppression command but that just opens two instances at once. Is there a way we can have it only go through the create new xboard routines only if there is an xboard instance already running, else ingnore all that and just load the png straight up?
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Minor correction, the command in the launch script is
$EXEC xboard "$@"
the $@ relays any arguments.
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Or just have it load up straight on the first time it receives an open signal and there after go into the new xboard intance routines on every signal after. We of course can then go back to the first suppression we had, in this case, because it would only be creating the new instance while a board was already open, and so the OS would suppress the first call, but not the xboard argument one. (I think?) This would still have a slight problem in the rare case where people had xboard already open and xboard was running an engine match, but they can be the ones confused, click on it again and have it open the new instance, right? Unless they are impatient like me and click on the file 4 times anyway XD
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: OSX Xboard 4.7.2 .app

Post by hgm »

The problem is that when XBoard is first started without any arguments, it brings up the GUI according to the saved settings, and starts the default engine. While the intention could have been to start it in -viewer mode (after clicking a .PGN), which might have invoked another engine through -viewerOptions, or to connect to FICS (after clicking a .xop settings file that contained a -ics option), etc. Not all of what it did in the initial startup with wrong options is easy to undo.

Of course a certain way to undo it is always react to the OpenFile signal by launching a new instance, (which will then be correctly started with the file argument through "open -n", knowing the argument from the beginning), and have the original instance commit suicide when only one instance was required (i.e. when 'suppress' was set). This could be achieved by putting

Code: Select all

if(suppress) exit();
at the end of StartNewXBoard(), and removing the earlier if(suppress) from there. This is extremely ugly, though, and would furthermore lead to the problem that any time you start up XBoard without any arguments, the first time you would click a PGN would kill that XBoard, even if the already running one was playing a game. So to guard against that it should base the suppress decision on the arrival time of the signal: if it arrives immediately after startup it is apparently OS X that has translated clicking on an associated file with an argumentless launch of XBoard followed by a signal, while if the signal comes much later, the initial launch must have been for another (valid) reason.

Of course we could also have XBoard wait for some time after startup, before having it do anything, to see if it gets the OpenFile signal, and suicide only when such a signal arrives during the timeout period. And then continue with the regular startup (bringing up the GUI) if no signal arrived before the timeout.

But I wonder if we cannot do a better job at misguiding OS X into doing the right thing. It seems that using "open -n" on a script does exert its influence also to $EXEC calls inside the script. I.e., when you $EXEC xboard-bin, OS X aparently doesn't again make the decision "I already have an xboard-bin running, so let's make it a signal". So I wonder if we cannot bootstrap ourselves through two levels of scripts: not associate PGN files with the xboard launch script, but with another script (say 'yboard'), which then contains the command "open -n -a xboard --args $@" (which seems to work if we issue it from XBoard with the system() function). The xboard script can then set the environment to be inherited by xboard-bin, as it does now.

Another idea, that might be worth a try: what happens if inside the xboard launch script we write

$EXEC open -n -a xboard-bin --arg $@

?
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

I put in
"$EXEC open -n -a "$bundle_contents/MacOS/$name-bin" --args "$@""
Thoes variables are all defined in the script, and being a script it has to know the directory as well.

I just get

Code: Select all

Joshuas-MacBook-Pro:~ herecomethej$ /Applications/Xboard/Xboard.app/Contents/MacOS/Xboard ; exit;
Xboard
/Applications/Xboard/Xboard.app/Contents/MacOS
logout
[Process completed]
----------------
Perhaps I'm not understanding what you mean. By rigging the signal to just open a FILE rather then go through the extra instance routines the command starting xboard would be simply

xboard file

not

xboard

Then on second and third open signals, we can have it create new instance routines all we like with 'xboard file'. Or maybe I'm not understanding what the signal is? I thought it was just a signal from the OS. i.e. we could have it trigger an espresso machine if we had the right hookup and a little code.
But we need to the signal in order for the silly OS to append 'file' after 'xboard' if we are opening just the file set to open with the xboard.app by the OS
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Or don't we? i just looked back at what Alun said. The signal is just for opening the file while xboard is already open, which we don't need if we can get it to just open multiple instances. I finally understand now!
-----------------------------
I have an idea. Have the app set to open a script that in turn opens the Launch script. This will trigger it to open a terminal window on the launch script, and you can have as many instances of xboard as you like. It will just keep opening windows (The os opens a terminal when you open a unix executable directly.) Problem is I find it ugly. Just another thing you have to quit when you had no real intention of using it. But it would work.
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: OSX Xboard 4.7.2 .app

Post by hgm »

Well, I guess that none of the latter methods can work if OS X simply refuses to pass the file argument in the first call to the associated application. The name of the clicked file is only supplied through the signal. So we must catch that signal.
JoshPettus
Posts: 730
Joined: Fri Oct 19, 2012 2:23 am

Re: OSX Xboard 4.7.2 .app

Post by JoshPettus »

Wow this is a headache the more I think about it. XD


So lets keep it to basics. We just use the signal to open the file as a method of starting xboard.

And xboard will be able to open multiple instances with the terminal 2nd launcher idea.

If they want to load a pgn file on active instance they can just go into the menu.

-----------
Crud...They must have changed how it works in 10.9 as this use to work in 10.8. If the app is active clicking on the app icon just switches to the active window. It doesn't even try to execute When I saw my brilliant terminal idea didn't work I tried to force it with the 2nd launch script with the

open -n -a xboard --args $@

if it were always sending an execute command when I clicked on the app it would have no choice but to open... Grrr I think I'll just have to go with the PGN Viewer.command script after all. could we still have the signal open up xboard from .pgn? People will just have to live with one window.