miguello,
If you are using JMP 14, there is a new command Get Data Table List() that returns a list of opened data tables. If you are not using JMP 14 then the N Table() command is required.
Also Subscribe to Data Table List(<subscriber>, OnOpen() | OnClose() | OnRename() ) is available on JMP 12, 13,14.
Below is a script to explore table subscriptions. Note instead of show ctbls, you could update the list on each change.
Final note, NTable() will "count" invisible data tables, but Private data tables are not counted.
Names Default To Here( 1 );
//---Use one of these functions
//---- JMP 14 function
//ctbls = Get Window List( Type("DataTables")) << Get Window Title();
// --- User function to returns a list of table names
curtbl_fn = Function({}, {nt, tlist={}, i},
nt= NTable();
If(nt >0,
For(i=1, i<=nt, i++,
Insert into(tlist, Data Table(i) << get name)
);
); // end if
tlist
); //end Function
//------ functions to handle when a new table is created, whe a table is renamed and when a table is closed.
fnew = Function( {dtab},
Insert Into(ctbls, dtab << Get Name );
show(ctbls, NTable())
);
fnnme = Function( {dtab, b},{i},
show(dtab, b);
i = contains(ctbls, b );
If (i>0, ctbls[i] = dtab << get name);
show(ctbls, NTable())
);
fclose = Function( {dtab}, {i},
i = contains(ctbls, dtab<<get name );
show(dtab, i);
If (i>0, remove from(ctbls, i));
show(ctbls, NTable());
);
Open("$Sample_Data/Variability Data/2 Factors Crossed.jmp");
Open("$Sample_Data/Baseball.jmp");
Open("$Sample_Data/Basketball.jmp");
Open("$Sample_Data/Football.jmp");
Open("$Sample_Data/Fishing.jmp");
Open("$Sample_Data/Pogo Jumps.jmp");
//_____________________________________________________________________
//--- Run to here ------------------------
//use the JMP 14 command or the functions
ctbls =curtbl_fn();
show(ctbls, NTable());
//--- Run to here and check the log------------------------
aSub = Subscribe to Data Table List( , OnOpen( fnew ) );
Subscribe to Data Table List( aSub, OnRename( fnnme ) );
Subscribe to Data Table List( aSub, OnClose( fclose ) );
dt = Open( "$SAMPLE_DATA/Iris.jmp" );
Wait( 2 );
dt << setname( "yyy" );
// two printouts: one for OnOpen() and one for OnRename()
//--- Run to here and check the log------------------------
Close(Data Table("Fishing"), NoSave);
//--- Run to here and check the log------------------------
//Check Table manipulations
Data Table("yyy") << Subset (All Rows, All Columns, Output Table Name ("Iris redux") );
//--- Run to here and check the log------------------------
Unsubscribe to Data Table List(asub, All);
print("should not do anything");
Close(Data Table("Baseball"), NoSave);