Events A sample “afterNew” eventListener 83
The following script is the one referred to by the preceding script. The file reference in the preceding script must match the location of this script on your disk. For the complete script, see
GetEventInfo.vbs
.
Rem GetEventInfo.vbs
Rem An InCopy CS6 VBScript
Rem
Rem Displays information about an Event object; called from an EventListener.
main evt
Function main(myEvent) myString = "Handling Event: " & myEvent.EventType
myString = myString & vbCr & vbCr & "Target: " & myEvent.Target & " " & myEvent.Target.Name
myString = myString & vbCr & "Current: " & myEvent.CurrentTarget & " " & myEvent.CurrentTarget.Name
myString = myString & vbCr & vbCr & "Phase: " & myGetPhaseName(myEvent.EventPhase) myString = myString & vbCr & "Captures: " & myEvent.Captures
myString = myString & vbCr & "Bubbles: " & myEvent.Bubbles
myString = myString & vbCr & vbCr & "Cancelable: " & myEvent.Cancelable
myString = myString & vbCr & "Stopped: " & myEvent.PropagationStopped
myString = myString & vbCr & "Canceled: " & myEvent.DefaultPrevented
myString = myString & vbCr & vbCr & "Time: " & myEvent.TimeStamp
MsgBox myString, vbOKOnly, "Event Details" end function
Rem Function returns a string corresponding to the event phase enumeration.
Function myGetPhaseName(myEventPhase)
Select Case myEventPhase
Case idEventPhases.idAtTarget
myPhaseName = "At Target"
Case idEventPhases.idBubblingPhase
myPhaseName = "Bubbling"
Case idEventPhases.idCapturingPhase
myPhaseName = "Capturing"
Case idEventPhases.idDone
myPhaseName = "Done"
Case idEventPhases.idNotDispatching
myPhaseName = "Not Dispatching" end select myGetPhaseName = myPhaseName
End Function
The following sample script shows how to turn off all
EventListeners
for the application object. For the complete script, see EventListenersOff.
Rem EventListenersOff.vbs
Rem An InCopy CS6 JavaScript
Rem
Rem Removes all event listeners from the application.
Set myInCopy = CreateObject("InCopy.Application")
For myCounter = 1 To myInCopy.EventListeners.Count
myInCopy.EventListeners.Item(1).Delete
Next
A sample “afterNew” eventListener
The afterNew
event provides a convenient place to add information to the document, like user name, document creation date, copyright information, and other job-tracking information. The following sample script shows how to add this sort of information to document metadata (also known as file info or XMP information). For the complete script listing, refer to the AfterNew tutorial script.
Events A sample “afterNew” eventListener 84
Set myInCopy = CreateObject("InCopy.Application")
Set myEventListener = myInCopy.EventListeners.Add("afterNew",
"c:\AfterNewHandler.vbs")
The following script is the one referred to by the preceding script. The file reference in the preceding script must match the location of this script on your disk. For the complete script, see
AfterNewHandler.vbs
.
Rem AfterNewHandler.vbs
Rem An InCopy CS6 VBScript
Rem
Rem Adds metadata to a new document.
myAddMetadata evt
Function myAddMetadata(myEvent)
Set myInCopy = CreateObject("InCopy.Application")
Set myDocument = myInCopy.Documents.Item(1) myInCopy.UserName = "Adobe"
With myDocument.MetadataPreferences
.Author = "Adobe Systems"
.Description = "This is a sample document with XMP metadata." & vbCr & "Created: " + myEvent.TimeStamp
End With
End Function