Storing Clips in a File
In this article, some simple functions will be enhanced, and others will be added, so that the relevant clips are stored in a file in addition to being displayed. This means that clips will be available to copy and paste anywhere when needed, simply by opening up the file of saved clips and copying the information from there to a target document.
The first task is to initialize a file variable so that clips can be stopred in the file. This simply means setting a filename to be used later in the program for storing clips.
This is achieved by the following comment and command before other commands are processsed:
; New add a filename variable to save the information.
The script now continues as before with:
to initialize the clipboard to null.
The next task is to ensure that the dialogue box displays when awaiting a clip to be collected from the clipboard by the user is always on top, so that it is constantly displayed. The user then clicks on the OK button to clear the dialogue. This achieved by changing the following command in the previous script:
MsgBox, Please select and copy data using the mouse and "control-c" and press "Ok" on this dialogue to continue:
MsgBox, 4096,,Please select and copy data using the mouse and "control-c" and press "Ok" on this dialogue to continue:
This ensures that the Msgtbox function always stays on top as the code, 4096 means stay on top. There are numerous other options available in this command, and other autohotkey commands. Generally, the options' section of each command determines how it will behave according to a specific situation.
Another factor is the need to await clipboard contents before continuing. At present, the program expects clipboard data to be available, even if the user has clicked on the button on the OK dialogue. However, if the user has not actually collected clipboard data by using the "cut" or "paste" functions (control c, control-x) then no clipboard data will be present. It is required that in this case, the program should wait until data is available on the clipboard. This is achieved by the following command which is now added to the code:
We can also add a dialogue to appear as soon as information appears on the clipboard, following the above "ClipWait" command. This is a MsgBox command with a timeout, requiring no user interaction as it will immediately disappear after three seconds due to the timeout value as follows:
MsgBox,,, Clipboard data collected!, 3
As we now plan to store the date and time into a file, rather than just output the information to the screen it makes sense to save the date time as a separate variable, instead of outputting all the information in one go. This way the date/time can be stored in the output file as well as displayed on the screen. This is achieved via the following variable assignment (assuming the time/values have been set):
vTimeDate := vMonthVal . "/" . vDayVal . "/" . vYearVal . " " . vTimeHour . ":" . vTimeMinutes
Finally, we record the information to a text file, in addition to displayed on the screen. The following command outputs the information into a file:
FileAppend, %vTimeDate%`n"%clipboard%"`n, %vFileName%