// TARGET:excel.exe // START_IN: using LoginPI.Engine.ScriptBase; using System.IO; public class fileSaveTimer : ScriptBase { private void Execute() { /* -Disclaimer: This workload is provided as-is and might need further configuration and customization to work successfully in each unique environment. For further Professional Services-based customization please consult with the Login VSI Support and Services team. Please refer to the Help Center section "Application Customization" for further self-help information regarding workload crafting and implementation. -Run the workload against the "target" using Script Editor to ensure it will work before uploading it and testing with it -Workload version and changelist: --V1.0 | original --V1.1 | updated Mar 31 2025 -Leave Application running compatibility: true Metadata: -Utilizing Microsoft Windows 11 Business; winver 1909; OS Build 10.0.26100 -ScriptEditor ver. 5.14.6. -Microsoft Office Excel 365 (version 16.0.18526.20168) ver. 1907 This script will: -Save a file to a specified location. For example: opening a large .xls file into Excel, then Save As the file to a defined path, then start a timer after file saving started, then stop the timer after the application's window title indicates the file's been saved, then close the application -Create file path and delete existing target file path, if necessary -Open defined application and the defined file path -Find the window title, which should be present once the initial file has loaded -Open the Save As dialog box with the defined keyboard shortcut -Wait for Save As dialog box to appear and find the File Name field -Type to the File Name field the defined file destination path; submit the Save As dialog -Start custom timer -Wait for a defined window title to be present, which should only be present once the destination file has finished saving -Stop the custom timer -Close the target application Please update the application launch path to include the file needing to be opened, such as: excel.exe c:\temp\mysheetinput.xlsx Please update the following variables: */ // For FileNameFieldControl variable, add the information for // the File Name input field in the Save As dialog box; example: // SaveAsWindow.FindControl(className : "Edit:Edit", // title : "File name:",timeout:GlobalTimeoutInSeconds); // Which is visible in Excel 2019 when the File Name field // in the Save As dialog box is present // This is for creating the path in which the file will be saved, // if it doesn't exist. This is so the target application won't // produce an error message such as "The specified directory // doesn't exist" when trying to save the file; example "c:\temp\" string OutputFileFolder = @"c:\temp\"; // To ensure the target application isn't running before the // START(); metafunction, put the process name of the target // application here; example: "excel*" string ProcessNameTaskkill = "*excel*"; // Define how long it should take maximum for operations to // complete, such as opening an Excel document, in seconds. // This script will fail, as designed, if this value is // surpassed; example: 60 int GlobalTimeoutInSeconds = 60; // Define here how many seconds to wait in between functions; // example: 5. This will allow for the target application's // UI to catch up double WaitSeconds = 0.5; // Define how many characters per minute the typing function // will type; example; 180 int CharactersPerMinuteToType = 180; // Put the path to save the file at; example: // "c:\temp\mysheetoutput.xlsx". Please note this will also // delete this file path first in this script, if it exists. // A UNC/network path would also work here string OutputFilePath = @"c:\temp\mysheetoutput.xlsx"; // Put the window title name that will be present once the // source file has been opened within it; example: // "*mysheetinput.xlsx*" string InitialWindowTitleName = "Excel"; // Put the keyboard shortcut that should open up the // application's Save As dialog; example: "{F12}" // (which will open the Save As dialog in Excel) string WhatToTypeToOpenSaveAs = "{F12}"; // Put the name of the target application's Window title // here; example: "*Save As*" string SaveAsDialogWindowTitleName = "*Save As*"; // Put the keystrokes combination to select all text and // clear out a field; example "{CTRL+a}{BACK}" -- which will // do ctrl+a -> backspace string KeystrokesToClearOutFilenameField = "{CTRL+a}{BACK}"; // Add the maximum amount of time the file save operation // should take in seconds; example: 60 // Note the script // will fail, by design, if this value threshold is surpassed int FileSaveTimeout = 60; // Put the string that should be present in the application's // title once the file has been save; example: // "*mysheetoutput.xlsx - Saved*" string WindowTitleAfterSave = "*mysheetoutput*"; // Ensuring the target application isn't already running ShellExecute("cmd /c taskkill /f /im " + ProcessNameTaskkill,waitForProcessEnd:true,timeout:GlobalTimeoutInSeconds); // These are file system prepare tasks if(File.Exists(OutputFilePath))// This will delete OutputFilePath variable path, if it exists { File.Delete(OutputFilePath); } // This will create the path in the OutputFileFolder variable, if it doesn't exist System.IO.Directory.CreateDirectory(OutputFileFolder); // This will start the application, looking for the defined filename in the title Wait(seconds: 3, showOnScreen: true, onScreenText: "Starting Excel"); START(mainWindowTitle:InitialWindowTitleName,timeout:GlobalTimeoutInSeconds); Wait(seconds:WaitSeconds); // If Excel opens to the document type selection page, uncomment the following line // to click on "Blank Document". If Word opens to a normal blank document, // leave the next line commented out. MainWindow.FindControl(className : "ListItem:NetUIListViewItem", title : "Blank workbook").Click(); // This will type the keyboard shortcut to open the Save As dialog Type(WhatToTypeToOpenSaveAs,cpm:CharactersPerMinuteToType,hideInLogging:false); // This will look for the window and bring it into focus var SaveAsWindow = FindWindow(title:SaveAsDialogWindowTitleName,timeout:GlobalTimeoutInSeconds); Wait(seconds:WaitSeconds); SaveAsWindow.Focus(); var FileNameFieldControl = SaveAsWindow.FindControl(className : "Edit:Edit", title : "File name:",timeout:GlobalTimeoutInSeconds); // Add the information for the File Name input field in the Save As dialog box; example: // SaveAsWindow.FindControl(className : "Edit:Edit", title : "File name:",timeout:GlobalTimeoutInSeconds); // Which is visible in Excel 2019 when the File Name field in the Save As dialog box is present Wait(seconds:WaitSeconds); FileNameFieldControl.Click(); // Will click the File Name field control Wait(seconds:WaitSeconds); Type(KeystrokesToClearOutFilenameField,cpm:CharactersPerMinuteToType); // Will type out the keystrokes to clear out the File Name field // The following will type in the OutputFilePath and type enter, to submit the Save As page/commit saving the file. Then a custom timer is started. Type(OutputFilePath +"{enter}",cpm:CharactersPerMinuteToType); StartTimer(name:"FileSavingTime"); FindWindow(title : WindowTitleAfterSave,timeout:FileSaveTimeout); // Will wait for the window title to be present, which should only be present once the file has saved StopTimer(name:"FileSavingTime"); // Stopping the custom timer Wait(seconds:WaitSeconds); STOP(); // This will close out of the application Wait(seconds:WaitSeconds); } }