
Dim FramePath, ProductDIR, ARG, Count
FramePath = "..\Source\books\"
Set WshShell = CreateObject("WScript.shell")


Sub CloseFM()
	If WshShell.AppActivate("Adobe FrameMaker") Then
		WshShell.SendKeys "%{F4}"
		WScript.Sleep 1000
		While WshShell.AppActivate("FrameMaker")
			WshShell.SendKeys "{Enter}"
			WScript.Sleep 1000
		Wend
	End If
End Sub


Sub WaitForWindow(WindowName)
	While Not WshShell.AppActivate(WindowName)
		WScript.Sleep 500
	Wend
  WScript.Sleep 1000
End Sub


'Update Book
CloseFM

Count = 0

WScript.Sleep 5000

For Each ARG in WScript.Arguments

If Count = 0 Then
	FramePath = FramePath & ARG & "\"
	Count = 1
Else

  WshShell.run FramePath & ARG & "\" & ARG & "_TOC.fm",1
  WaitForWindow "Adobe FrameMaker"
  
  WScript.Sleep 1500

  WshShell.run FramePath & ARG & "\" & ARG & ".book",1

  WaitForWindow "Adobe FrameMaker"

  WScript.Sleep 8000

  WshShell.SendKeys "^A"
  WScript.Sleep 500

  WshShell.SendKeys "%FIO{Tab}PCLTEURFM{Enter}", Wait
  WScript.Sleep 10000

  CloseFM
End If

Next