Skip to main content
Inspiring
May 19, 2025
Answered

Notification Script Issues

  • May 19, 2025
  • 2 replies
  • 626 views

I am using a variation of @Russ Ward 's 06.01 Notification script from here: http://www.weststreetconsulting.com/WSC_ExtendScriptSamples.htm

 

I want the script to run a second script when a document is first opened and when the active document changes.

 

Right now, the script just shows some confirmation dialogs, instead of running the other script. Here is the script:

Notification(Constants.FA_Note_PostActiveDocChange, true);
Notification(Constants.FA_Note_PreQuitSession, true);

function Notify(note, object, sparam, iparam)
{
    switch (note) 
    {
        case Constants.FA_Note_PostActiveDocChange:
//            alert("The active doc changed");
            var doc = app.ActiveDoc;
            if (doc.ObjectValid()){
                var returnVal = confirm("The active doc changed: \n\nDo you want to keep receiving this notification?");
                
                if(returnVal == 0)
                {
                    Notification(Constants.FA_Note_PostActiveDocChange , false);
                }
            }    
            break;         
//            win.close         
    
    case Constants.FA_Note_PreQuitSession:
        Notification(Constants.FA_Note_PostActiveDocChange , false);
        Notification(Constants.FA_Note_PreQuitSession , false);
        alert("closing script");
        break;
    
    }
}

I'm running into the followings issues:

  • The PostActiveDocChange notification seems to fire when I first open FM, even though there is no active doc. I tried to work around that with my "if" statement above, but it didn't seem to work. That's a minor annoyance for the confirmation statement, but for the script I want to launch, it is going to show an error message about not having an active document and needing to quit, so I want to avoid that.
  • Related, if instead of closing Framemaker, I close the last document that was open, I also get the message, even though there is no active document. This will cause a similar error.
  • The PostActiveDocChange notification seems to fire twice when I open a file, then it works normally. Minor issue. My script closes all open user-palettes (pop-up windows) and opens a new one. So when first opening a document, the pop-up is going to appear, close, and re-open - probably look like flicker. Not a big deal, but not ideal either.
  • Originally, I had an issue with the script staying active even after I  closed and re-opened FrameMaker. The PreQuitSession notification seems to handle that. Originally, I tried post-quit session and that didn't work.

Thanks in advance!!!

Correct answer Marshall_Brooks

Resolved - although a bit of an odd solution.

 

I had the script set to autorun so I could see what happened when you first opened FrameMaker before a document was active.

 

I unregistered the script and re-loaded it and I was seeing the I'm here messages.

 

I had to remove the script from auto-run and re-enter if for the changes to take effect. Apparently, FM was using the previous version of the script and not re-opening it from the saved version on the hard drive like I would have expected.

 

With the updated version of the script, I don't get the notification when FM first starts up nor when the last document closes. So there isn't a valid current document at that point.

 

Apparently, FM thinks that the active document changes when the last open document is close (which somewhat makes sense), and when the program first opens and there is no active document - which doesn't really make sense.

 

I guess the double prompt when opening a file (still happens), is the same type of thing, the current active document is closing, and the new one is opening.

 

But odd that if I switch between open documents, I only get one prompt.

 

 

 

 

 

2 replies

frameexpert
Community Expert
Community Expert
May 19, 2025

One other thing to note; this is unnecessary:

var doc = app.ActiveDoc;

The object parameter will be the new active document (Doc) object, so you can use this:

var doc = object;

 

Inspiring
May 19, 2025

Reboot didn't help. But something is wrong with my script, b/c I should at least be seeing the "I'm here" alert message.

Marshall_BrooksAuthorCorrect answer
Inspiring
May 20, 2025

Resolved - although a bit of an odd solution.

 

I had the script set to autorun so I could see what happened when you first opened FrameMaker before a document was active.

 

I unregistered the script and re-loaded it and I was seeing the I'm here messages.

 

I had to remove the script from auto-run and re-enter if for the changes to take effect. Apparently, FM was using the previous version of the script and not re-opening it from the saved version on the hard drive like I would have expected.

 

With the updated version of the script, I don't get the notification when FM first starts up nor when the last document closes. So there isn't a valid current document at that point.

 

Apparently, FM thinks that the active document changes when the last open document is close (which somewhat makes sense), and when the program first opens and there is no active document - which doesn't really make sense.

 

I guess the double prompt when opening a file (still happens), is the same type of thing, the current active document is closing, and the new one is opening.

 

But odd that if I switch between open documents, I only get one prompt.

 

 

 

 

 

frameexpert
Community Expert
Community Expert
May 19, 2025

It could be that the Welcome window is seen as a document. Try displaying the document's Label property and see what it says.

Inspiring
May 19, 2025

I have the welcome window turned off, but I guess I should account for that for others.

 

I added " alert(doc.label);" after the if (doc.ObjectValid) statement, but I never saw anything display. Also added "alert("I'm here!") and nothing displayed.

 

I'm going to try to re-boot and see what that does.

 

I've used doc = app.ActiveDoc forever - probably from some of your scripts - LOL!!!