Windows NightWatchman API
NightWatchman helper APIs
Method | Description |
---|---|
ActivateApp |
Activates the specified application window. This method is similar to Inputs
Returns
ExampleTo activate the application specified by h1 = NwmScript.ActivateApp(hWnd); |
BackupDirectory |
Returns the user specific directory for NightWatchman backups. This directory is set by NightWatchman to: C:\documents and settings\<username>\application data\1e\NightWatchman\ where Inputs
Returns
ExampleTo return the backup directory for the current logged on user: Dir = BackupDirectory(); |
ClickButton |
Performs the operation of the mouse clicking the specified dialog button by sending a Inputs
Returns
ExampleTo simulate the mouse clicking the OK button in window h1: NwmScript.ClickButton(h1, "OK"); |
ClickMouse |
Performs the operation of clicking the specified mouse button. This method includes code to compensate for switched mouse buttons so scripting can always assume right-handed operation. It is assumed that the cursor has already been positioned before this method is called. See Inputs
Returns
ExampleTo position the mouse cursor on the Cancel button and click it in window h1 : NwmScript.SelectSubItem(h1, "Cancel"); NwmScript.ClickMouse("L"); |
CloseActiveAppDialogs |
Closes active dialogs the specified application may have open by selecting the Cancel and Close buttons. This guarantees the application is in a state ready for operations. This should be executed at the start of a script after the helper object is instantiated. The input field uses the regular expression facility for text mapping. To find the whole string Inputs
Returns
ExampleTo close active dialogs open in Microsoft Word: NwmScript.CloseActiveAppDialogs("Microsoft Word"); |
CloseActiveAppDialogsLike |
Closes active dialogs, like the specified class, the specified application may have open, by selecting the Cancel and Close buttons. This guarantees the application is in a state ready for operations. This should be executed at the start of a script after the helper object is instantiated. The input field uses the regular expression facility for text mapping. To find the whole string Inputs
Returns
ExampleTo close active dialogs open in Microsoft Word: CloseActiveAppDialogsLike("Microsoft Word", "#32770"); |
CopyFile |
Copies a file from one location to another. The extension parameter is used as the extension might not be included in the filename due to user's Explorer settings. The method first attempts to copy the file specified. If this fails, a second attempt is made using the extension specified. If a file to be copied has zero length, Inputs
Returns
ExampleTo copy NwmScript.CopyFile("guide.doc", "c:\temp\guide.doc", ".doc") |
DeactivateApp |
Deactivates the currently selected application so that another can be selected. This is primarily required when accessing complicated applications that host embedded application windows running in another process. Deactivating the current application process and selecting another will allow you to find and manipulate windows in that process Inputs
Returns
ExampleTo deactivate the application h1 = NwmScript.DeactivateApp(); |
ExpectCancel |
Cancels a call to ExpectWindow . The parameter is the ID returned from the call to Inputs
Returns
ExampleTo set an ExpectId = NwmScript.ExpectWindow("Save As", "", NewName + "{WAIT_500}%S"); NwmScript.ExpectCancel(ExpectId); |
ExpectWindow |
Specifies an operation to be performed on the appearance of a window specified by a search string or its title. This method may cause an exit from the Inputs
Returns
ExampleTo wait for a Save As window and type the string 'Doc1.Doc ' into the active Filename text box: ExpectId = NwmScript.ExpectWindow("Save As", "", "Doc1.Doc") |
FindInvisibleWindowLike |
Allows you specify a search string to find an application window that is hidden. This is similar to the Windows API Inputs
Returns
ExampleTo search for open windows with a title that starts with the text 'Visio:' hWnd = NwmScript.FindInvisibleWindowLike(0, 0, "", "^Visio.*"); To search for the highest level dependent window of the application h1 = hWinMain while((h2 = (HWND) FindInvisibleWindowLike((long) h1, 0, "", ""))!=0) { h3 = h4; SetForegroundWindow ((long) h3); } |
FindWindowLike |
Allows you specify a search string to find an application window. This is similar to the Windows API Inputs
Returns
ExampleTo search for open windows with a title that starts with the text ' Visio:' hWnd = NwmScript.FindWindowLike(0, 0, "", "^Visio.*"); To search for the highest level dependent window of application h1 = hWinMain while((h2 = (HWND) FindWindowLike((long) h1, 0, "", ""))!=0) { h3 = h4; SetForegroundWindow ((long) h3); } |
GetAccItem |
Retrieves the value of a specified item in an active window. The Name and Role fields are retrieved from the Windows Accessibility parameters. The depth parameter reduces the recursion depth. This should be kept as low as possible to increase the efficiency of this method. NoteTo assist with writing scripts, a third-party tool such as UI Spy, UI Verify or Spy++ can help to determine Windows Accessibility role and control names. These tools are freely available on-line. Inputs
Returns
ExampleTo search the window section of window h1, for the item label 'File name:' and return the value in it's edit box: FileName = NwmScript.GetAccItem(h1, 3, "File name:", "window", ", "title bar"); |
GetActiveObject |
Creates an application object. Similar to the NoteThis method can only be used for applications which expose an application scripting class. Using the returned pointer will allow access to Word settings and functions directly. For example, Inputs
Returns
ExampleTo return a pointer to the Word object application: Set ObjApp = NwmScript.GetActiveObject("Word.Application") |
GetCmdLine |
Gets the full command line path of the executing program. Inputs
Returns
ExampleIf the following command were executed within a notepad script, CmdLine = NwmScript.GetCmdLine(); |
GetCurrDir |
Returns the result of a Inputs
Returns
ExampleTo return the current directory: CurrentDir = GetCurrDir() |
GetEnvVar |
Gets the value of the Environment variable specified. Inputs
Returns
ExampleIn this example, the if (DlgFileName!=FileName) { SavePath = DlgFileName.replace(FileName,""); if(debug & 1) WScript.Echo("Bad SavePath : " + SavePath); SavePath = NwmScript.GetEnvVar("=" + SavePath.toUpperCase(), 1); } WScript.Echo ("SavePath : " + SavePath); NewName = NwmScript.MakeNWMFilename(FileName, ".txt", SavePath); |
GetFullPath |
Gets the full path of a specified file. This function removes the complexity of extracting the absolute pathname from the Inputs
Returns
ExampleThe following example should resolve the following scenarios:
DlgFileName = GetAccItem(h, 7, "File name:", "editable text") Fullpath = GetFullPath(FileName, DlgFileName) |
GetWindowText |
Gets the specified window title Inputs
Returns
ExampleTo return a window's WndwName = NwmScript.GetWindowText(hWnd); |
Log |
This method may be used to add data to script specific log files as defined in the property Inputs
Returns
ExampleTo write 'Error' to the NightWatchman error log. NwmScript.Log("Error"); |
MakeNWMFilename |
Adds the NightWatchman tag and current date to the passed file name or replaces it if it already exists. It then returns this new filename. The filename created is of the format Inputs
Returns
ExampleThe NewName variable holds the returned formated NewName = NwmScript.MakeNWMFilename(thisDoc.Name, ".doc", DocPath); http://confluence.1e.com/pages/editpage.action?pageId=47909655# |
MoveFile |
Inputs
Returns
ExampleTo move a text file from its current location to the temp directory: NwmScript.MoveFile("guide.doc", "c:\temp\guide.doc", ".txt"); |
SelectAccItem |
Makes the specified item active. The Name and Role fields are compared against the Windows Accessibility parameters. To assist with script writing, the Inputs
Returns
ExampleTo search the window section of window h1 for the item label 'File name:' and make it active. Useful when inserting filenames in Save As boxes. FileName = NwmScript.SelectAccItem(h1, 3, "File name:", "window", ", "title bar"); |
SelectSubItem |
Makes an item in a window active so that subsequent mouse clicks will work. Inputs
Returns
ExampleTo select the Cancel button on the activate window: NwmScript.SelectSubItem(h1, "Cancel"); |
SendKeys |
Sends key strokes to the active application. The syntax for the For example, "(filea+b.txt)" Inputs
Returns
ExampleThis will send the keys ALT, F, A NwmScript.SendKeys("%FA"); |
SendKeysToWindow |
Send keystrokes to a specified window. The syntax for the Inputs
Returns
ExampleTo send the keys ALT, F, A to the active dialog: NwmScript.SendKeysToWindow(hWnd, "%FA"); |
SendKeysToDialog |
Sends key strokes to the active dialog. Sometimes the child control within a dialog may not properly pass key presses to their parent. This problem can be avoided by sending the keys to the dialog containing the focused control instead. The syntax for the Inputs
ReturnsAlways returns ExampleTo send keys to the active dialog: NwmScript.SendKeysToDialog("%FA"); |
SetActiveWindow |
Makes the window specified active. Inputs
Returns
ExampleTo set the window specified by window handle h1, to active: NwmScript.SetActiveWindow(h1); |
WaitForWindow |
Waits for the window specified to be created. Inputs
Returns
ExampleTo wait for an application's h1 = NwmScript.WaitForWindow(hWnd, 0, ", "Save As"); |
WaitWindowGone |
This method waits for the specified window to close. You can also use this method to check for "expected" windows with Inputs
Returns
ExampleTo wait for the window specified by window handle h1 to be gone: NwmScript.WaitWindowGone(h1); |
WriteToBackupList |
This method will log the name of a backed up file to NoteUse of this backup file is a requirement if you want to allow end-users to view the files backed up by NightWatchman. Inputs
Returns
ExampleTo add the name of the backed-up file, X = NwmScript.WriteToBackupFile(DocPath + NewNm, OrigNm); |