Close all journals with one exceptionI am looking for a line of script code that allows me to close all open journals except one window.
Acutally the extraction of the correct name list does not work. It is then not possible to match it to journal name that should stay open. See below script *** .
CloseAllJournalsExcept = Function( {},
JournalName = "StaysOpen";
For( i = N Items( Window() ), i > 0, i--,
If( Window( i ) << GetName != JournalName, //***
Window( i ) << close window()
)
);
);
Thanks.
Re: Close all journals with one exception
Use findAll(journals) to make a list of journals, and use loc() to help remove the keeper from the list. Then send the closeWindow command to the list. Below, the locked icon is appended to each journal to tell JMP "this journal is locked, create another journal next time, rather than adding to this one". Otherwise it is hard to make a bunch of journals. The journals are also marked setDirty(0) so there is no prompt when closing them. You might not want that for the one you keep open.
myJrns = {};
For( i = 1, i <= 5, i += 1,
w = New Window( Char( i ), V List Box( Text Box( Char( i ) ) ) );
j = w << journalwindow;
w << closewindow;
j[Text Box( 1 )] << sibAppend( Icon Box( "Locked" ) ); // locked: just to make a new window each time
Insert Into( myJrns, j );
);
myJrns << setDirty( 0 ); // these were just created, make it easy to close them
// get a list of all open journals
alljournals = Find All( Journals );
// close all but the 2nd one just created...
// myJrns[...] is the list of journals just created
// myJrns[2] is the 2nd one that we decide to keep
// the allJournals list might be in a different order, so
// use loc() to find the matching index in allJournals
keeper = Loc( alljournals, myJrns[2] ); // returns a matrix
keeper = keeper[1]; // was a matrix of one element, now a scalar
// modify the allJournals list so we can close all of its items
Remove From( allJournals, keeper ); // remove the keeper from the list
allJournals << closewindow; // closes all the journals that remain in the list