Skip to main content
Braniac
May 2, 2022
Answered

Keyboard shortcut to select book

  • May 2, 2022
  • 2 replies
  • 424 views

Hi,

 

I do almost everything with keyboard shortcuts. When I have a book open and a file of the book and close this file, then the Welcome Screen is selected and not the book.

Is there a keyboard shortcut to select the book?

I could not find anything in the online help or in other forum posts.

 

Best regards

 

Winfried

    This topic has been closed for replies.
    Correct answer frameexpert

    These things are always more complicated than they look on the surface :-). Save this to a text file and put this in the startup folder and it should do the switching to the active book automatically when the last active document is closed. Any feedback is appreciated.

    #target framemaker
    
    var CP = CP || {};
    
    CP.getAllOpenVisibleDocs = function () {
    	
    	var docs, doc;
    	
    	docs = [];
    	
    	doc = app.FirstOpenDoc;
    	while (doc.ObjectValid () === 1) {
    		if ((doc.IsOnScreen === 1) && (doc.Label !== "Structure View")) {
    			docs.push (doc);
    		}
    		doc = doc.NextOpenDocInSession;
    	}
    	
    	return docs;	
    };
    
    Notification (Constants.FA_Note_PostQuitDoc, true);
    
    function Notify (note, object, sparam, iparam) {
    	
    	var docs, book;
        
        switch (note) {
                
            case Constants.FA_Note_PostQuitDoc:
    		
    		// See how many documents are open and visible.
    		// The Welcome screen will not report as the active document.
    		docs = CP.getAllOpenVisibleDocs ();
    		if (docs.length === 0) {
    			// No active document; see if a book is open.
    			book = app.FirstOpenBook;
    			if (book.ObjectValid () === 1) {
    				// A book is open; make it active.
    				app.ActiveBook = book;
    				book.IsInFront = 1;
    			}
    		}
    		break;
        }
    }
    

    2 replies

    Braniac
    May 2, 2022

    I forgot to mention that I close the regular file with CTRL+F4 (or CTRL+W).

    CTRL+Tab does not work.

    ALT+Tab switches to other applications.

    frameexpert
    frameexpertCorrect answer
    Braniac
    May 2, 2022

    These things are always more complicated than they look on the surface :-). Save this to a text file and put this in the startup folder and it should do the switching to the active book automatically when the last active document is closed. Any feedback is appreciated.

    #target framemaker
    
    var CP = CP || {};
    
    CP.getAllOpenVisibleDocs = function () {
    	
    	var docs, doc;
    	
    	docs = [];
    	
    	doc = app.FirstOpenDoc;
    	while (doc.ObjectValid () === 1) {
    		if ((doc.IsOnScreen === 1) && (doc.Label !== "Structure View")) {
    			docs.push (doc);
    		}
    		doc = doc.NextOpenDocInSession;
    	}
    	
    	return docs;	
    };
    
    Notification (Constants.FA_Note_PostQuitDoc, true);
    
    function Notify (note, object, sparam, iparam) {
    	
    	var docs, book;
        
        switch (note) {
                
            case Constants.FA_Note_PostQuitDoc:
    		
    		// See how many documents are open and visible.
    		// The Welcome screen will not report as the active document.
    		docs = CP.getAllOpenVisibleDocs ();
    		if (docs.length === 0) {
    			// No active document; see if a book is open.
    			book = app.FirstOpenBook;
    			if (book.ObjectValid () === 1) {
    				// A book is open; make it active.
    				app.ActiveBook = book;
    				book.IsInFront = 1;
    			}
    		}
    		break;
        }
    }
    
    Braniac
    May 2, 2022

    Hi Rick,

     

    Thank you very much! This works perfectly!

    I am sorry, when I caused you this extra work!

     

    Best regards

     

    Winfried

    frameexpert
    Braniac
    May 2, 2022

    This code appears to work. What would you want to use for a keyboard shortcut?

    #target framemaker
    
    var doc, book;
    
    // Test for an active document.
    // The Welcome screen will not report as the active document.
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 0) {
    	// No active document; see if a book is open.
    	book = app.FirstOpenBook;
    	if (book.ObjectValid () === 1) {
    		// A book is open; make it active.
    		app.ActiveBook = book;
    	}
    
    Braniac
    May 2, 2022

    Hi Rick,

     

    I would prefer a general shortcut. Isn't there anything to just switch between all open documents _and_ books?

    With your script the book file would be automatically selected, when the last regular file would have been closed?

     

    Best regards

     

    Winfried

    frameexpert
    Braniac
    May 2, 2022

    Yes, it would only switch to the open book if no other documents were open. But you are right, there may be a general shortcut to switch back and forth, which would be more useful. Let me look around and see if there is one.