Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Notification Script Issues

Enthusiast ,
May 19, 2025 May 19, 2025

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!!!

TOPICS
Scripting
560
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , May 20, 2025 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 th

...
Translate
Community Expert ,
May 19, 2025 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 19, 2025 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!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2025 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;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 19, 2025 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 20, 2025 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.

 

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2025 May 20, 2025

> 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.

 

Scripts are loaded into memory at FrameMaker startup so any changes you make won't be picked up until you restart FrameMaker. You can bypass this by running the script after making changes so that a fresh copy gets loaded into memory.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 20, 2025 May 20, 2025
LATEST

@ frameexpert :

 

>Scripts are loaded into memory at FrameMaker startup so any changes you make won't be picked up until you restart FrameMaker. You can bypass this by running the script after making changes so that a fresh copy gets loaded into memory.

 

That was what I would have expected, not what I was seeing. Changes were not picked up when I restarted FM. Changes were not picked up when I re-booted the PC. Changes were not picked up until I removed the script from autorun and re-added it to autorun.

 

Not sure why ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines