photools.com Community

BOARD ARCHIVE => IMatch 5 Scripting and Apps => Topic started by: DavidOfMA on January 03, 2016, 06:44:18 PM

Title: Getting a script to run on application close
Post by: DavidOfMA on January 03, 2016, 06:44:18 PM
I'd like to call John Z's script that writes pending metadata and refreshes data-driven categories from the Application script, imatch5.bas. I have two questions, the answers to which are probably obvious but which I can't figure out from the Help.

1. How should the file be structured? When the editor creates the script, it looks like this:

Code: [Select]
Sub Main

End Sub

Private Sub Application_Quit()

End Sub

To complete it, I want to call a modified version of John's script in Sub Application_Quit. Do I also need to call Application_Quit from Sub Main? If so, do I just insert Application_Quit() in Sub Main, like so:
Code: [Select]
Sub Main
Application_Quit()
End Sub

2. Is this the correct way to call another script from within a script?
Code: [Select]
Private Sub Application_Quit()
MacroRun (C:\ProgramData\photools.com\IMatch5\scripts\user\Writeback And Refresh (auto).bas)
End Sub

Thanks. Sorry about these obvious questions, but I'm not a script writer and I haven't been able to get this to work. I'm sure it's something very simple I'm doing wrong.

David
Title: Re: Getting a script to run on application close
Post by: JohnZeman on January 03, 2016, 08:50:56 PM
2. Is this the correct way to call another script from within a script?
Code: [Select]
Private Sub Application_Quit()
MacroRun (C:\ProgramData\photools.com\IMatch5\scripts\user\Writeback And Refresh (auto).bas)
End Sub

Since I've never tried using an application script (let alone writing one) I'm going to pass on all but your last question.  To run a different script from within the one you're working on you can do something like this (which is a copy and paste from one of my scripts).

Code: [Select]
MacroRun MacroDir & "\Image Info Popup.bas" 'Run the Image Info Script
Title: Re: Getting a script to run on application close
Post by: thrinn on January 03, 2016, 10:22:09 PM
Quote
Do I also need to call Application_Quit from Sub Main?
No, this Sub will be called automatically. More technically: it represents an event handler for event "Quit" of the Application object. Whenever the event occurs, the Basic runtime environment will take care of calling the associated event handlppppler.
Title: Re: Getting a script to run on application close
Post by: DavidOfMA on January 03, 2016, 11:15:37 PM
It doesn't appear that the Application_Quit subroutine, which should call the script that writes the pending metadata and updates the data-driven categories, is called when I quit IMatch. This is the entire contents of my IMatch5.bas file:

Code: [Select]
Sub Main

End Sub

Private Sub Application_Quit()
MacroRun ("C:\ProgramData\photools.com\IMatch5\scripts\user\Writeback and Refresh (auto).bas")
End Sub

What am I doing wrong?

David