Here's a first working shot at an external, programmatic mechanism for opening .mw worksheets/Documents as new tabs in an already running Maple Standard GUI session.
This involves a `sh` shell script, runnable in Unix/Linux/OSX/cygwin. Maybe someone could post a MS-Windows .bat batch file equivalent.
The basic idea is this: you have a GUI session open. But you want to be able to open other .mw files in that session without having to go through the GUI's File->Open menu every time (since that doesn't remember position, or stay open, etc). Also, you may not want an entirely new Maple GUI instance to be fired up with every workeheet you try to open by double-clicking .mw files on your desktop.
You should be able to configure your own operating system filemanager to associate the .mw filename extension with some action. Except instead of having .mw associated with the Maple Standard GUI they'd instead be associated with this new shell script. With such an association, you'd just have to double-click .mw file icons in your favourite OS file manager in order to have them get opened as new tabs in your already running Maple GUI. Of course, if there is no instance of the Maple GUI already running then the script is supposed to start one up to open the selected file.
There are three files involved here. One is a shell script, in plain text. Another is a Maple commandline plain text file, which gets called by the shell script. And another is a .mw worksheet containing a few lines of Maple code. I'll put all of their contents below.
The .mw contents are as follows. This needn't necessarily go in a .mw file. It might also go inside one's .mapleinit file. The last Maple command here will never return, so any other work done in this GUI session will have to be done in a new worksheet/Document (with a new kernel) using File/New (just once).
------- server code, name it any .mw filename you want -------
serverfcn := proc(sid)
Now comes the commandline maple code.
------- client code, save this in automw.mpl ---------
# This runs a single procedure with no arguments.
# That procedure gets a worksheet filename from the
# shell variable "fname".
# It then attempts to open a Socket on port 2525 and,
# if successful, sends a command to open the file
# as a worksheet.
# If unsuccessful, it issues a system call to open the
# file in an entirely new xmaple session.
local fn, str, sid, sopened;
sid := Sockets:-Open("localhost.localdomain",2525);
sopened := true;
if sopened=true then
Sockets:-Write(sid, cat( "INTERFACE_WORKSHEET(display,file=`",fn,"`)" ));
str := cat("maple12 -s -x ",fn);
And lastly comes the shell script.
------- shell script, name it automw -------
# This is the shell script which starts the worksheet
# autoloader client (commandline maple file automw.mpl)
# The variable fname is assigned the first arg of this
# shell script. The commandline maple script can grab that.
maple12 -s -q automw.mpl &
To see it work, open a Maple GUI session and execute the .mw server code above (or open the .mw file to which you saved it). Don't worry that the prompt never returned after you axecute the Sockets:-Serve command. Then run the automw shell script with the name of some .mw file as its argument. If things are working then that .mw should open in a new tab in the already running GUI.
You can notice that the shell script assumes that `maple12` is in your PATH and is how you fire up Maple 12. It assumes that localhost.localdomain works for your machine. You may need to adjust these things.
Of course, you'll want to make the automw shell script executable, with `chmod u+x automw`.
If anyone has any directions on how to associate a script with a filename extension in their favourite OS filemanager, that might be useful here.
The experts may wonder why I did not run the Sockets:-Serve call inside a Maple Thread, so that control would be returned to the main parent thread and hence avoiding any need for opened a new worksheet following execution of the server code. I have not been able to get that to work. If it worked then the server code go nicely be placed entirely out of view in one's .mapleinit file.
As always, improvements, comments, and fixes are welcome.