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"

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.

TabControl typeControl nameMessage ExampleNotes
1EditstrFileToLoadSet strFileToLoad “C:\myfile.csv”
1ButtonExec ButtonSelectFileToLoadInteractive use only1
1EditstrFileHeaderSet strFileHeader “ID,Name,City”
1ButtonExec ButtonPreviewFileInteractive use only
1RadioradGetHeaderSet radGetHeader 1
1RadioradSetHeaderSet radSetHeader 1
1EditstrFieldDelimiter1Set strFieldDelimiter1 ;
1EditstrFieldEncapsulator1Set strFieldEncapsulator1 *
1CheckboxblnMultiline1Set blnMultiline1 1Send message Exec ChangedMultiline1 to unhide the control strEndoflineReplacement1
1EditstrEndoflineReplacement1Set strEndoflineReplacement1 ¶
1DropDownListstrFileEncoding1Choose strFileEncoding1 UTF-8
1ButtonExec ButtonLoadFileWill prompt the user if CSV Buddy already contains data
1ButtonExec ButtonLoadFileAddWill add the current content without prompting the user
1ButtonExec ButtonLoadFileReplaceWill replace the current content without prompting the user
1ButtonExec ButtonCreateNewFileInteractive use only
2EditstrRenameSet strRename “ID,Full Name,City”
2ButtonExec ButtonSetRename
2ButtonExec ButtonUndoRename
2EditstrOrderSet strOrder “Name,City,ID”
2ButtonExec ButtonSetOrder
2ButtonExec btnUndoOrder
2EditstrSelectSet strSelect “Name,City”
2ButtonExec ButtonSetSelect
2ButtonExec ButtonUndoSelect
2EditstrMergeSet strMerge “[Last Name], [First Name]”
2EditstrMergeNewNameSet strMergeNewName “Full Name”
2ButtonExec ButtonSetMerge
2ButtonExec btnUndoMerge
3EditstrFileToSaveSet strFileToSave “C:\myfile-changed.csv”
3ButtonExec ButtonSelectFileToSaveInteractive use only
3EditstrFieldDelimiter3Set strFieldDelimiter3 ;
3EditstrFieldEncapsulator3Set strFieldEncapsulator3 *
3RadioradSaveWithHeaderSet radSaveWithHeader 1
3RadioradSaveNoHeaderSet radSaveNoHeader 1
3RadioradSaveMultilineSet radSaveMultiline 1
3RadioradSaveSinglelineSet radSaveSingleline 1
3EditstrEndoflineReplacement3Set strEndoflineReplacement3 ¶
3DropDownListstrFileEncoding3Choose strFileEncoding1 UTF-8Values: ANSI, UTF-8, UTF-16, UTF-8-RAW, UTF-16-RAW or CPnnn
This encoding is also used in the 4) Export tab.
3ButtonExec ButtonSaveFileWill prompt the user if file exists
3ButtonExec ButtonSaveFileOverwriteWill overwrite the existing file without prompting the user
3ButtonExec ButtonCheckFileInteractive use only
4EditstrFileToExportSet strFileToExport “C:\myexport.txt”
4ButtonExec ButtonSelectFileToExportInteractive use only
4RadioradFixedSet radFixed 1
4RadioradHTMLSet radHTML 1
4RadioradXMLSet radXML 1
4RadioradExpressSet radExpress 1
4ButtonExec ButtonExportFile
4EditstrMultiPurposeSet strMultiPurpose “String”
4ButtonExec ButtonMultiPurposeInteractive use only, change default width or select HTML template
4ButtonExec ButtonCheckExportFileInteractive use only
5EditstrFontNameLabelsSet strFontNameLabels “Microsoft Sans Serif”
5EditstrFontNameEditSet strFontNameEdit “Courier New”
5EditstrFontNameListSet strFontNameList “Microsoft Sans Serif”
5EditstrListBackgroundColorSet strListBackgroundColor D0D0D0
5EditstrListTextColorSet strListTextColor 000000
5EditstrFontSizeLabelsSet strFontSizeLabels 12
5EditstrFontSizeEditSet strFontSizeEdit 11
5EditstrFontSizeListSet strFontSizeList 10
5EditintSreenHeightCorrectionSet intSreenHeightCorrection -100
5EditintSreenWidthCorrectionSet intSreenWidthCorrection -100
5EditstrTextEditorExeSet strTextEditorExe “notepad.exe”
5DropDownListstrRecordEditorChoose drpRecordEditor “Full screen”Values: Full screen or Field-by-field
5DropDownListstrDefaultEileEncodingChoose drpDefaultEileEncoding UTF-8Values: ANSI, UTF-8, UTF-16, UTF-8-RAW, UTF-16-RAW or CPnnn
5EditstrCodePageLoadSet strCodePageLoad 1242
5EditstrCodePageSaveSet strCodePageSave 1242
5CheckboxblnAlwaysEncapsulateSet blnAlwaysEncapsulate 1
5CheckboxblnSkipHelpReadyToEditSet blnSkipHelpReadyToEdit 1
5CheckboxblnListGridSet blnListGrid 1
5EditintDefaultWidthSet intDefaultWidth 16
5EditstrTemplateDelimiterSet strTemplateDelimiter ~
5EditstrMergeDelimitersSet strMergeDelimiters []
5ButtonExec ButtonSaveOptions
6ButtonExec ButtonCheck4Update
6ButtonExec 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 .

TabTab 1Switch 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.
WindowWindow MaximizeOther possible values are: Minimize and Restore
DebugDebug 1Pauses 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.
ExitExitExit the current script file (script only)
SleepSleep nPause the script execution for n milliseconds
TimeoutTimeout 120000Sets 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).
DelimDelim*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


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:

ValueMessage displayed after CSV Messenger execution
0Silent: no dialog box or command line message shown after CSV Messenger commands
1Errors only: display a dialog box only when an error occurred in CSV Buddy (default)
2Always: after each command executed in CSV Buddy, display a dialog box (on launch errors) or a command line message (on success or command errors)


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:

; comment #1
' comment #2