CSV Buddy Scripting
CSV Messenger allows to set the value of various CSV Buddy’s controls (text fields, radio buttons, checkboxes, etc.) in order to configure a task (like open file, edit columns, save or export file, etc.) and then trigger this task as if you were clicking on a button. Here are lists of the various types of controls and of the scripting commands.
Main commands
- Set: The Set command defines the value of Edit, Checkbox and Radio button controls. The value can be a string or a number as specified in the documentation.
- Choose: The Choose command selects an item in a dropdown list.
- Exec: The Exec command triggers the action associated with a button.
Control types
- Edit: The content of edit fields (text boxes like CSV file to load in the first tab) can be defined with the Set command before executing commands. For example:
Set strFileToLoad "c:\path\file.csv"
- Checkbox: Before executing a command, checkboxes in CSV Buddy (like Multi-line fields) can be turned on (1) or off (0) using the Set command. For example:
Set blnMultiline1 1
- Radio button: Before executing a command, an item in a group of radio buttons (like Get header from file) can be selected using the Set command and the value 1. For example:
Set radSetHeader 1
- DropDownList: The selected item in a dropdown lists (like the encoding list in tab 1) can be chosen with the Choose command before executing commands. For example:
Choose strFileEncoding1 UTF-8
- Button: Finally, the CSV Messenger command Exec allows to trigger the commands associated buttons (like Load button) found in tabs 1) Load CSV File, 2) Edit Columns, 3) Save CSV File, etc. For example:
Exec ButtonLoadFile
.
Sending Messages
Messages are commands sent to CSV Buddy using its companion program CSV Messenger. These commands can be sent from the command line or using a script file. The file CSVMessenger-n_n-32-bit.exe
is distributed with version information in its name. It is recommended to rename this file to CSVMessenger.exe
to avoid having to change your commands files when a new version of CSV Messenger is released.
You can run this file from any folder, at your convenience. Before sending a message to CSV Buddy, make sure one (and only one) instance of CSB Buddy is running.
Sending messages from the command line
You can send single messages from the command line (or from the Windows Run command, a batch file, PowerShell script, a context menu command, etc.) like in the following examples (adapt the path to your own configuration). The available messages are described in the table below. NOTE: You must enclose parameters that include spaces between double-quotes.
C:\>"C:\Apps\CSV Buddy\CSVMessenger.exe" Set strFileToLoad "C:\my file.csv" C:\>"C:\Apps\CSV Buddy\CSVMessenger.exe" Set strFieldDelimiter1 , C:\>"C:\Apps\CSV Buddy\CSVMessenger.exe" Exec ButtonLoadFile
In the example above, the first line sets the file to load, the second line sets the field delimiter to semi-colon (;) and the third line load the file in CSV Buddy. See other examples at the bottom of this page.
Sending commands using a script file
You can also send a list of commands in a script file. Each line of the script must contain one command. Command sections are separated with the pipe (|) character (this delimiter can be changed with the command Delim
). For example, a script file executing the actions shown in the previous example would be:
Set|strFileToLoad|"c:\my files.csv" Set|strFieldDelimiter1|; Exec|ButtonLoadFile
To launch your script, use CSVMessenger with, as parameter, the path to the script file. For example:
C:\>"C:\Apps\CSV Buddy\CSVMessenger.exe" "c:\my files\my script.txt"
Controls and commands
This table lists the controls found on each CSV Buddy tabs. Use the controls names in your messages with commands Set, Choose or Exec.
Tab | Control type | Control name | Message Example | Notes |
---|---|---|---|---|
1 | Edit | strFileToLoad | Set strFileToLoad “C:\myfile.csv” | |
1 | Button | Exec ButtonSelectFileToLoad | Interactive use only1 | |
1 | Edit | strFileHeader | Set strFileHeader “ID,Name,City” | |
1 | Button | Exec ButtonPreviewFile | Interactive use only | |
1 | Radio | radGetHeader | Set radGetHeader 1 | |
1 | Radio | radSetHeader | Set radSetHeader 1 | |
1 | Edit | strFieldDelimiter1 | Set strFieldDelimiter1 ; | |
1 | Edit | strFieldEncapsulator1 | Set strFieldEncapsulator1 * | |
1 | Checkbox | blnMultiline1 | Set blnMultiline1 1 | Send message Exec ChangedMultiline1 to unhide the control strEndoflineReplacement1 |
1 | Edit | strEndoflineReplacement1 | Set strEndoflineReplacement1 ¶ | |
1 | DropDownList | strFileEncoding1 | Choose strFileEncoding1 UTF-8 | |
1 | Button | Exec ButtonLoadFile | Will prompt the user if CSV Buddy already contains data | |
1 | Button | Exec ButtonLoadFileAdd | Will add the current content without prompting the user | |
1 | Button | Exec ButtonLoadFileReplace | Will replace the current content without prompting the user | |
1 | Button | Exec ButtonCreateNewFile | Interactive use only | |
2 | Edit | strRename | Set strRename “ID,Full Name,City” | |
2 | Button | Exec ButtonSetRename | ||
2 | Button | Exec ButtonUndoRename | ||
2 | Edit | strOrder | Set strOrder “Name,City,ID” | |
2 | Button | Exec ButtonSetOrder | ||
2 | Button | Exec btnUndoOrder | ||
2 | Edit | strSelect | Set strSelect “Name,City” | |
2 | Button | Exec ButtonSetSelect | ||
2 | Button | Exec ButtonUndoSelect | ||
2 | Edit | strMerge | Set strMerge “[Last Name], [First Name]” | |
2 | Edit | strMergeNewName | Set strMergeNewName “Full Name” | |
2 | Button | Exec ButtonSetMerge | ||
2 | Button | Exec btnUndoMerge | ||
3 | Edit | strFileToSave | Set strFileToSave “C:\myfile-changed.csv” | |
3 | Button | Exec ButtonSelectFileToSave | Interactive use only | |
3 | Edit | strFieldDelimiter3 | Set strFieldDelimiter3 ; | |
3 | Edit | strFieldEncapsulator3 | Set strFieldEncapsulator3 * | |
3 | Radio | radSaveWithHeader | Set radSaveWithHeader 1 | |
3 | Radio | radSaveNoHeader | Set radSaveNoHeader 1 | |
3 | Radio | radSaveMultiline | Set radSaveMultiline 1 | |
3 | Radio | radSaveSingleline | Set radSaveSingleline 1 | |
3 | Edit | strEndoflineReplacement3 | Set strEndoflineReplacement3 ¶ | |
3 | DropDownList | strFileEncoding3 | Choose strFileEncoding1 UTF-8 | Values: ANSI, UTF-8, UTF-16, UTF-8-RAW, UTF-16-RAW or CPnnn This encoding is also used in the 4) Export tab. |
3 | Button | Exec ButtonSaveFile | Will prompt the user if file exists | |
3 | Button | Exec ButtonSaveFileOverwrite | Will overwrite the existing file without prompting the user | |
3 | Button | Exec ButtonCheckFile | Interactive use only | |
4 | Edit | strFileToExport | Set strFileToExport “C:\myexport.txt” | |
4 | Button | Exec ButtonSelectFileToExport | Interactive use only | |
4 | Radio | radFixed | Set radFixed 1 | |
4 | Radio | radHTML | Set radHTML 1 | |
4 | Radio | radXML | Set radXML 1 | |
4 | Radio | radExpress | Set radExpress 1 | |
4 | Button | Exec ButtonExportFile | ||
4 | Edit | strMultiPurpose | Set strMultiPurpose “String” | |
4 | Button | Exec ButtonMultiPurpose | Interactive use only, change default width or select HTML template | |
4 | Button | Exec ButtonCheckExportFile | Interactive use only | |
5 | Edit | strFontNameLabels | Set strFontNameLabels “Microsoft Sans Serif” | |
5 | Edit | strFontNameEdit | Set strFontNameEdit “Courier New” | |
5 | Edit | strFontNameList | Set strFontNameList “Microsoft Sans Serif” | |
5 | Edit | strListBackgroundColor | Set strListBackgroundColor D0D0D0 | |
5 | Edit | strListTextColor | Set strListTextColor 000000 | |
5 | Edit | strFontSizeLabels | Set strFontSizeLabels 12 | |
5 | Edit | strFontSizeEdit | Set strFontSizeEdit 11 | |
5 | Edit | strFontSizeList | Set strFontSizeList 10 | |
5 | Edit | intSreenHeightCorrection | Set intSreenHeightCorrection -100 | |
5 | Edit | intSreenWidthCorrection | Set intSreenWidthCorrection -100 | |
5 | Edit | strTextEditorExe | Set strTextEditorExe “notepad.exe” | |
5 | DropDownList | strRecordEditor | Choose drpRecordEditor “Full screen” | Values: Full screen or Field-by-field |
5 | DropDownList | strDefaultEileEncoding | Choose drpDefaultEileEncoding UTF-8 | Values: ANSI, UTF-8, UTF-16, UTF-8-RAW, UTF-16-RAW or CPnnn |
5 | Edit | strCodePageLoad | Set strCodePageLoad 1242 | |
5 | Edit | strCodePageSave | Set strCodePageSave 1242 | |
5 | Checkbox | blnAlwaysEncapsulate | Set blnAlwaysEncapsulate 1 | |
5 | Checkbox | blnSkipHelpReadyToEdit | Set blnSkipHelpReadyToEdit 1 | |
5 | Checkbox | blnListGrid | Set blnListGrid 1 | |
5 | Edit | intDefaultWidth | Set intDefaultWidth 16 | |
5 | Edit | strTemplateDelimiter | Set strTemplateDelimiter ~ | |
5 | Edit | strMergeDelimiters | Set strMergeDelimiters [] | |
5 | Button | Exec ButtonSaveOptions | ||
6 | Button | Exec ButtonCheck4Update | ||
6 | Button | Exec ButtonDonate |
1 Interactive use only: these commands can only when a user is interacting with the application.
Other Commands
These commands can also be used in your command line messages (except if tagged “script only”) or in your script file .
Command | Example | Notes |
---|---|---|
Tab | Tab 1 | Switch the user interface to the specified tab; other possible values are: 2, 3, 4, 5 and 6 Note: it is not required to switch to a given tab to set its control’s content but it helps seeing the actions being executed as your script progress. |
Window | Window Maximize | Other possible values are: Minimize and Restore |
Debug | Debug 1 | Pauses before executing each command with a prompt to continue or stop the script; other possible value is: 0. Note: This value is persistent to the CSV Buddy session (use “Debug 0” to turn debug mode off). Debug mode is always off when starting CSV Buddy. |
Exit | Exit | Exit the current script file (script only) |
Sleep | Sleep n | Pause the script execution for n milliseconds |
Timeout | Timeout 120000 | Sets the timeout to 120000 milliseconds (2 minutes). This value is saved to CSVBuddy.ini. See the section MessengerTimeout below. Each time CSV Buddy is launched, it resets this value to its default 30000 (30 seconds). |
Delim | Delim* | Change the internal delimiter replacing | (pipe) for messages in CSV Messenger scripts. Note that there is no space between “Delim” and the delimiter replacement. See Script Example below. |
CSVBuddy.ini values for CSV Messenger
MessengerVerbose
The value MessengerVerbose
under the section [Messenger]
in CSVBuddy.ini controls what is displayed by CSV Messenger after the execution of a command. The default value is 1 (Error only). MessengerVerbose cans have these values:
Value | Message displayed after CSV Messenger execution |
---|---|
0 | Silent: no dialog box or command line message shown after CSV Messenger commands |
1 | Errors only: display a dialog box only when an error occurred in CSV Buddy (default) |
2 | Always: after each command executed in CSV Buddy, display a dialog box (on launch errors) or a command line message (on success or command errors) |
MessengerTimeout
The value MessengerTimeout
under the section [Messenger]
in CSVBuddy.ini controls the delay allowed to CSV Buddy to complete a command sent by CSV Messenger. If the delay is exceeded, the command is completed by CSV Buddy but CSV Messenger will return a error to its caller. This will have an impact only if the caller (the batch file, for example) reacts to an error code from CSV Messenger.
The default value in milliseconds is 30000 (30 seconds). This default value is set each time CSV Buddy is launched. It can be changed with the command “Timeout 200000” (to change the delay to 2 minutes). This value is saved for future uses of CSV Messenger until CSV Buddy is relaunched.
Batch file example
You can send a series of messages using a Windows batch file like this:
C:\>C:\Apps\CSV Buddy\MyBatch.bat
The file MyBatch.bat must contain one call to CSVMessenger.exe per line (you may need to add the path to CSVMessenger.exe or add the program to you Windows PATH variable). In this example, the example file TEST-CountryCodes.csv is loaded in CSV Buddy and converted from comma delimited to semi-colon delimiters:
CSVMessenger.exe Tab 1 CSVMessenger.exe Set strFileToLoad "c:\myfiles\TEST-CountryCodes.csv" CSVMessenger.exe Set strFieldDelimiter1 , CSVMessenger.exe Exec ButtonLoadFile CSVMessenger.exe Tab 3 CSVMessenger.exe Set strFileToSave "c:\myfiles\TEST-CountryCodes-semicolon.csv" CSVMessenger.exe Set strFieldDelimiter3 ; CSVMessenger.exe Exec ButtonSaveFileOverwrite
Script example
You can also send a series of messages using a script file like this:
C:\>"C:\Apps\CSV Buddy\CSVMessenger.exe" "c:\my files\my script.txt"
The file myscript.txt must contain one message per line. Different sections of the message must be separated by the pipe (|) delimiter (this delimiter can be changed with the command Delim
). Lines starting with ‘ or ; are treated as comments and are not processed. In this example, a file comma delimited is loaded in CSV Buddy and saved with semi-colon delimiters:
Tab|1 Set|strFileToLoad|c:\myfiles\TEST-CountryCodes.csv Set|strFieldDelimiter1|, Exec|ButtonLoadFile ; comment #1 Tab|3 Set|strFileToSave|c:\myfiles\TEST-CountryCodes-semicolon.csv Set|strFieldDelimiter3|; Exec|ButtonSaveFileOverwrite ' comment #2