J Viewer: launch JQT and load a source file

32 views
Skip to first unread message

Ed Gottsman

unread,
Apr 12, 2024, 9:04:41 AMApr 12
to fo...@jsoftware.com
Greetings.  Norman Drinkwater got me thinking about running the J Viewer as a standalone application so as to cut down on interference with development work (particularly if you’re developing with wd, when interference is rife).

I mentioned it at last night’s wiki meeting, and Raul told me that on the Mac, it actually is possible to launch multiple sessions of an application using the terminal (2!:0):

(2!:0) 'open -na jqt.app'


…will open a second JQT session as if it were the most natural thing in the world. (Something similar is possible in Windows, apparently.)


So that gets me half-way to a keyboard shortcut that will not only launch a new JQT session but open the Viewer. All I need is a way to load the script:


'~addons/gottsman63/jwikiviz/run.ijs


…as part of the “open” command.  (Obviously I can convert the ~ with jpath as part of the shortcut line.)


I’ve searched and experimented without success.  I actually asked ChatGPT* for a solution.  It provided four plausible-looking candidates, the closest of which was:

1. Command Line Argument

If you're using the macOS Terminal to launch JQT, you can specify the script file directly as a command-line argument when launching the application. This approach is similar to using the open command with an argument for the file to open. Here’s how you can do it:

  1. Navigate to the location of the JQT application in Terminal. It might be in your /Applications directory if installed normally.

  2. Use the open command with the -a option (specify application) and provide the path to the .ijs file you want to load:

    bash
    open -na /Applications/jqt.app --args path/to/your/script.ijs

    Replace path/to/your/script.ijs with the actual path to your .ijs file.

So I tried:


(2!:0) 'open -na jqt.app --args /applications/j9.5/addons/gottsman63/jwikiviz/run.ijs'


…which launched JQT but did not load the Viewer.  I’ve occasionally found ChatGPT capable of hallucinating a perfect-looking solution to my problem—perhaps that’s what happened here.


Any help would be greatly appreciated.


Many thanks.


Ed


*I’ve found that for Python and JavaScript, ChatGPT is excellent at dealing with questions that begin, “This ought to be possible, I just can’t work out the syntax…”  I’ve also found that it’s confident-but-hopeless when it comes to J, a commentary perhaps on how far outside the mainstream J finds itself (to quote Maxwell Smart: “And…loving it.”).


Gilles Kirouac

unread,
Apr 13, 2024, 11:21:41 PMApr 13
to fo...@jsoftware.com
Ed -- if it's no too late.

I can't be of much help as I don't use a Mac and am not familiar with
MacOS.

Nevertheless the page on Starting J offers suggestions for debugging,
such as starting Jconsole and checking what scripts are loaded with
>4!:3'' .

https://code.jsoftware.com/wiki/System/Starting_J


With the task scheduler of MS-Win, I use:

path-to-jqt.exe -js "load 'path-to-myscript.ijs'" "myverb'' "
NB. use monospace font for this line

~ Gilles
> To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
>

Devon McCormick

unread,
Apr 14, 2024, 4:47:18 AMApr 14
to fo...@jsoftware.com
Would it help to read parameters from the command line?  I have jobs I invoke from DOS with command line arguments either labeled or positionally: would this help?

In any case, here's something I just put up about J's startup sequence which may be of use though it dates from 2017 - https://code.jsoftware.com/wiki/NYCJUG/2017-07-11#J.E2.80.99s_Startup_Sequence - and below.

Devon
---

= J's Startup Sequence =

1. The command line is parsed into words. The words are assigned to the variable ARGV_z_. The first word is the name of the J executable. The subsequent words, the parameters, tell J what to do. The first parameter that is not a switch is the name of the command script which is the J script you want to execute.

2. If the first parameter is the -jijx switch, the normal J IDE window, where you type commands and see them executed, will not be created. You must have a fully standalone application. Except for creating the IDE window, the J startup sequence will be followed as described below, and the -jprofile switch will be honored.

3. If the command line contains the -jprofile switch, you are taking full control of J's startup. Your command script will be executed instead of J's normal start sequence. Make sure you get it right! If the command script is omitted, J will skip the startup sequence entirely.

4. If you don't specify the -jprofile switch, you get J's normal startup sequence which winds up by executing the command script. The normal startup sequence is contained in the script ~bin\profile.ijs, which goes through the following steps:

    1. The variable SystemFolders_j_ is created, containing the paths J uses to get to your home directory, the system, etc. You can look at this variable after J has started to see what folders are defined. If you want to change these directories, you do so by creating the script ~bin\profilex.ijs. Use ~bin\profilex_template.ijs as the template for creating your custom script.
   
    2. Any missing directories referred to in SystemFolders_j_ are created.
   
    3. Normal startup continues by running ~system\util\boot.ijs. This file loads the J system files stdlib.ijs, scripts.ijs, regex.ijs, task.ijs, configure.ijs, ctag.ijs, jadetag.ijs, and (if appropriate), 'qt.ijs'. Use 4!:3 to see all the scripts that are loaded at startup.
   
    4. Next, if the J executable was Jconsole, the console window is created and the console startup file ~config/startup_console.ijs is executed. User customization is not performed.
   
    5. If the J executable was not Jconsole, the user customization steps are performed:
   
        1. The J IDE is loaded and the configuration files are executed:

   1. the user configuration from the Edit|Configure menu
   
   2. the addons configuration file ~addons\config\config.ijs.
   
        2. After configuration, the user startup script is executed. This script is contained in the Edit|Configure|Startup Script menu. This script is where you put the definitions that you want executed every time J starts. It is executed in the base locale.

    6. Finally, the command script is loaded if there is one. Normally this is a file, but if the inline script indicator -js is given in place of the name of the command script, the words of ARGV_z_ following the -jsare taken to be lines of J code, and they are put into the verb ARGVVERB which is used as the command script. The command script is executed in the base locale. If the command script is omitted, nothing is run.

5. When the startup sequence finishes, J may wait for user input. This input may come from a form, or, if -jijx was not specified, from the IDE window; but if neither of these sources of input exists, the interpreter will exit with no prompt. If your program expects input from another source, such as a timer or socket interrupt, you need to display a dummy form to keep J from terminating.
--

Devon McCormick, CFA

Quantitative Consultant


Ed Gottsman

unread,
Apr 14, 2024, 5:43:50 PMApr 14
to fo...@jsoftware.com
Gilles, Devon,

Many thanks for responding (and, no, it's not too late).

Norman very kindly produced shell/cmd files that solve the problem.  I am however oppressed by the belief that there must be a way to get the same effect with a (much simpler) user key shortcut. 

Each platform will require its own shortcut solution, and since you’ve got Windows expertise, we should start with it.  (Note that in a real version of the commands that follow, I’d be using > {. ARGV to invoke JQT, not the literal “…/jqt.exe".)

This line in a CMD prompt starts JQT and loads the Viewer:

“C:\Program Files\J9.5\bin\jqt.exe” -js “load jpath ‘~addons/gottsman63/jwikiviz/run.ijs’”

…but the Terminal ends up on top of the Viewer, which is suboptimal.  This line in CMD starts JQT:

“C:\Program Files\J9.5\bin\jqt.exe” -ijix -js “load jpath ‘~addons/gottsman63/jwikiviz/run.ijs’”

…but produces the error:

not found: C:/Users/edwar/-ijix

|file name error in script, executing monad 0!:0

|nonexistent file or invalid filename 

| 0!:0 y[4!:55<'y'

|[-134] C:\Program Files\J9.5\system\util\boot.ijs


And this line in CMD starts JQT:

“C:\Program Files\J9.5\bin\jqt.exe” -ijix “load jpath ‘~addons/gottsman63/jwikiviz/run.ijs’”

…but produces the same error:

not found: C:/Users/edwar/-ijix

|file name error in script, executing monad 0!:0

|nonexistent file or invalid filename 

| 0!:0 y[4!:55<'y'

|[-134] C:\Program Files\J9.5\system\util\boot.ijs


As does the command:


“C:\Program Files\J9.5\bin\jqt.exe” -ijix “C:/program files/j9.5/addons/gottsman63/jwikiviz/run.ijs"


I’ve tried several other variations of these commands without success.


Any idea what I might be doing wrong?


Thanks again.


Ed

chris burke

unread,
Apr 14, 2024, 6:09:28 PMApr 14
to fo...@jsoftware.com
> .…but the Terminal ends up on top of the Viewer, which is suboptimal.

You probably don't want to show the Terminal at all. Try:

“C:\Program Files\J9.5\bin\jqt.exe” -js “load
‘~addons/gottsman63/jwikiviz/run.ijs’ [ wd 'ide hide'"

The "ijix" error is because it is not a valid startup parameter, see
https://code.jsoftware.com/wiki/System/Starting_J .

Ed Gottsman

unread,
Apr 14, 2024, 6:15:26 PMApr 14
to fo...@jsoftware.com
Sweet Georgia Brown. Chris, many thanks.

(Now I’ll dig into Mac and Linux.)

Ed

Devon McCormick

unread,
Apr 14, 2024, 6:46:41 PMApr 14
to fo...@jsoftware.com
The parameter is "-jijx".

chris burke

unread,
Apr 14, 2024, 6:59:27 PMApr 14
to fo...@jsoftware.com
> The parameter is "-jijx".

That parameter was for J6 and earlier. See
https://code.jsoftware.com/wiki/System/Starting_J for the current
command line parameters.

Raul Miller

unread,
Apr 14, 2024, 9:59:28 PMApr 14
to fo...@jsoftware.com
I would invoke the wd'ide hide' after run.ijs rather than before (so
that if there's any errors in the initial load of run, the error
message would be visible.

FYI,

--
Raul
Reply all
Reply to author
Forward
0 new messages