I'm bumping this topic with some new findings, maybe it will help someone. I was trying to do something similar as @Djtjhin and encountered all the same problems described here, which I mostly solved thanks to the discussion here.
What I can add is the explanation of the weird behavior described by @txnelson. The issue is that if you subscribe without explicitly stating the subscription name as below:
asub = Subscribe to data table list( , OnOpen( Show("opening...") ) )
a new subscription under a new generic name ("_DTListSubscriber123") is created each time you run the script, increasing counter at the end.
The trick is either to explicitly name the subscriber so that you overwrite the same one each time you run the script, e.g.:
asub = Subscribe to data table list( "MyDTLSub1", OnOpen( Show("opening...") ) )
or to unsubscribe at the end, e.g. in the <<On Close statement of the window:
Unsubscribe to data table list( asub, "ALL" )
In other news, @Djtjhin, for renaming it's works pretty simply, it seems the event is triggered AFTER renaming, so Get Data Table List() gets you the new name(s). But I was pulling my hair out from a different reason, before making it work, due to lack of documentation. In contrast to OnOpen and OnClose, the OnRename function needs 2 arguments (new and old name/table), otherwise you'll be getting errors. And although in this particular listbox example you don't actually need them, if you do, you also have to keep in mind they are of different variable type, one is a table, the other a string (see below).
Names Default To Here(1);
f = Function ( { new_name_as_table, old_name_as_string },
print(asub||" renaming: "|| old_name_as_string || " to " || (new_name_as_table << get name) );
lb << set items( Get Data table List() );
);
asub = Subscribe to data table list( "MySub", OnRename( f ) );
nw = new window("Trial",show menu(0),
<< On Close(Unsubscribe to data table list( asub, "ALL")),
vlistbox(
lb = listbox(get data table list ());
)
);
dt = Open( "$SAMPLE_DATA/Tiretread.jmp" );
dt << set name( (dt<<get name) || "_renamed" );
Otherwise I agree with general sentiment that the subscriber it's very hard to work with, you have to be really careful to tie up all the loose ends. Better documentation would be much appreciated.