Script Language Reference

GLOBAL FUNCTIONS


Command Description
addMenuItem Creates menu item
echo Information box with text and button OK
inputText Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box
sleep Stops script execution for number of miliseconds
pspadVersion Returns PSPad version
getVarValue Returns any PSPad variable
moduleExists Returns version of module, if module doesn't exists, returns empty string
moduleVersion Returns file name of module, if module doesn't exists, returns empty string
moduleFileName Returns module filename include last backslash
modulePath returns module file path include last backslash
closeEditorByTitle Closes editor by filename
closeEditorByIndex Closes editor by index
closeAllEditors Closes all editor windows
newEditor Creates new object for editor handling
editorsCount Number of currently open editors
setClipboardText Stores text into clipboard
getClipboardText Returns text from clipboad
runPSPadAction Runs any PSPad action
 
 

EDITOR OBJECT FUNCTIONS


Command Description
activate Set focus to editor
appendText Appends text to editor end
assignActiveEditor Assign active editor window into object and show it
assignEditorByIndex Assign editor window to object by editor index
assignEditorByName Assign editor window to object by file name
assignLog This function is obsolete and is replaced with logXXXXX() functions
caretX Sets/returns editor CaretX position
caretY Sets/returns editor CaretY position
closeFile Closes file
command Runs editor command processor command
fileName Sets/returns editor file name
lineText Replaces/returns content of active line
linesCount Returns editor lines count
newFile Creates new file in PSPad. File name is optional
openFile Opens existing file in new editor window
openFileFromFTP Opens file using FTP
printFile Print editor
readOnly Set or return current editor read only (R/O) status
reloadFile Reload file
saveFile Saves file
saveFileAs Saves file as
saveFileToFTP Saves file to current FTP directory
selText Replaces/returns selected text from editor
setBlockBegin Sets begin of block selection
setBlockEnd Sets End of block selection
blockBeginX Returns block selection bounds, begin X
blockBeginY Returns block selection bounds, begin y
blockEndX Returns block selection bounds, end x
blockEndY Returns block selection bounds, end y
selStart Returns/sets selection start
selLength Returns/sets selection length
selectionMode Sets selection mode - C:column, L:line, N:normal
setCaretPos Sets editor caret position. -1 in parameter mean no change coordinate
text Replaces/returns all editor text
 
 

LOG ACCESS FUNCTIONS


Command Description
logClear Clears whole LOG window content
logAddLine Adds new line into LOG
logGetLine Returns line from LOG, identified by index parameter (numbered from 0)
logSetLine Sets log line, identified by index
logLinesCount Sets log line, identified by index
 
 

PROJECT ACCESS FUNCTIONS


Command Description
projectSave Save current project
projectFilesCount Number of files in current project
projectFiles File path including filename
projectFileName Project file path including filename
 
 

FTP FUNCTIONS


Command Description
ftpConnect Connect to predefined FTP connection
ftpDisconnect Disconnect FTP server
ftpCommand Send command to FTP server, e.g.. "CWD \public\www"
ftpDownloadFile Download file using FTP
ftpUploadFile Upload file using FTP
 
 

addMenuItem(caption: string; submenu: string; procedure: string; [shortcut: string]): Long(1)

Creates menu item. If you don't want submenu, send empty string as parameter. It is contained in script Init subroutine and works only during Init phase. All other calling is ignored. "&" may be used in caption to assign menu shortcuts. Caption set as "-" creates a line divider. More infomation about shortcut keys is found here. Shortcuts are optional.

Example VBscript
' Subroutine "Init" Is required 
' It Is called automatically during initialization To create menu items. 
Sub Init
    menuName = "&" & module_name
    addMenuItem "&Main method"         , menuName, "Main"
    addMenuItem "PSPad &version"       , menuName, "Demo1"
    addMenuItem "Script module version", menuName, "Demo2", "CTRL+ALT+1"
    addMenuItem "Open &script file"    , menuName, "openScript"
    addMenuItem "-"                    , menuName, ""
    addMenuItem "&Log Access"          , menuName, "DemoLog"
End Sub
 
Example JavaScript
// Subroutine "Init" Is required 
// It Is called automatically during initialization To create menu items. 
function Init() {
    menuName = "&" + module_name;
    addMenuItem("&Main method"         , menuName, "Main");
    addMenuItem("PSPad &version"       , menuName, "Demo1");
    addMenuItem("Script module version", menuName, "Demo2", "CTRL+ALT+2");
    addMenuItem("Open &script file"    , menuName, "openScript");
    addMenuItem("-"                    , menuName, "");
    addMenuItem("&Log Access"          , menuName, "DemoLog");
}
 
Example Python
def Init():
  pspad.addMenuItem("Example function", "PySample sample", "beispiel")
  pspad.addMenuItem("Version", "PySample sample", "version")  
  pspad.addMenuItem("Selection", "PySample sample", "selection")
 
Back to Top

echo(text: string): void

Information box with text and button OK.

Example VBscript
echo "Hello World!"
 
Example JavaScript
echo("Hello World!")
 
Back to Top

inputText(prompt: string, default: string[, cancel: string]): string

Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box. If user clicks "Cancel" a empty string is returned, or value of optional cancel parameter.

Back to Top

sleep(ms: integer): void

Stops script execution for number of miliseconds.

Example VBscript
Sub FindToDos
    Set SH = Wscript.CreateObject("WScript.Shell")
    SH.AppActivate "PSPad"
    Sleep(100)
    '// Send Alt + F
    SH.SendKeys "^f"
    Sleep(100)
    SH.SendKeys "todo"
    Sleep(100)
    '// Sends the shortcut for the ok button. = Alt+O
    SH.SendKeys "%l"
End Sub
 
Back to Top

pspadVersion(): string

Returns PSPad version.

Example VBscript
echo "PSPad version : " & pspadVersion()
 
Example JavaScript
echo("PSPad version : " + pspadVersion());
 
Example Python
def version():
  version = 'pspad version: %s\n' % pspad.pspadVersion()
  pspad.echo(version)
 
Back to Top

getVarValue(variable: string)[, filename: string]:string

Returns any PSPad variable. Second parameter is optional, is used fo filename related variables.

Example VBscript
test = getVarValue("%UserName%")
echo(test)
 
Back to Top

moduleExists(name: string):boolean

Returns version of module, if module doesn't exists, returns empty string.

Back to Top

moduleVersion(name: string):string

Returns file name of module, if module doesn't exists, returns empty string.

Example VBscript
echo "Module version: " & moduleVersion(module_name)
 
Example JavaScript
echo("Module version: " + moduleVersion(module_name));
 
Example Python
def version():
  version = 'module version: %s' % pspad.moduleVersion('PySample')
  pspad.echo(version)
 
Back to Top

moduleFileName(file_name: string): boolean

Returns module filename include last backslash.

Back to Top

modulePath():string

returns module file path include last backslash.

Back to Top

closeEditorByTitle(file_name: string): boolean

Closes editor by filename.

Back to Top

closeEditorByIndex(index: integer): boolean

Closes editor by index.

Back to Top

closeAllEditors(): void

Closes all editor windows.

Back to Top

newEditor(): object

Creates new object for editor handling.

Example VBscript
Set editor = newEditor()
editor.assignActiveEditor
handleSelText = editor.selText
 
Example JavaScript
var obj1 = newEditor(); //New editor object
obj1.openFile(moduleFileName(module_name)); // Open actual script file
var s = obj1.Text(); //returns all text from window 1
 
Back to Top

editorsCount():integer

Number of currently open editors.

Back to Top

setClipboardText(text: string)

Stores text into clipboard.

Back to Top

getClipboardText(): string

Returns text from clipboad.

Back to Top

runPSPadAction(action: string)

Runs any PSPad action. Click here for a list of comands.

Example VBscript
Const module_name = "RunAction" 'this name must be unique !!! 
Const module_ver = "0.001" 'version 

Sub Procedure
  Set obj = NewEditor()
  For i = 0 To editorsCount - 1
    obj.assignEditorByIndex(i)
    obj.activate
    If i = 0 Then 'For first file we Call user convertor selector 
      runPSPadAction "aUserConvertors"
    Else 'For all other files we run last used convertor 
      runPSPadAction "aLastUserConvertor"
    End If 
  Next 
End Sub 

' name "Init" Is required, its called automatically during initialization To create menu items 
Sub Init
  addMenuItem "Run action demo (convert all Open files)","", "Procedure"
End Sub

 
Back to Top

activate(): boolean

Set focus to editor. Return a value of True/1 on success

Back to Top

appendText(string): boolean

Appends text to editor end.

Back to Top

assignActiveEditor(): boolean

Assign active editor window into object and show it.

Example VBscript
Sub replaceRegExp
    Pattern = InputBox("Enter RegExp.", module_name, "([^\n\r]+)[\n\r]{1,2}")
    msg = "Enter replacement text for RegExp /" & Pattern & "/."
    newtext = InputBox(msg, module_name, "$1\+\+\+")
    text = handleSelText("")
    text = runRegExpReplace(text, Pattern, newtext)
    handleSelText text
End Sub

Private Function runRegExpReplace(haystack, Pattern, newtext)
    Set regEx = New RegExp
    If Pattern = "" Then
        runRegExpReplace = haystack
        Exit Function
    End If
    regEx.Pattern    = Pattern
    regEx.IgnoreCase = TRUE
    regEx.Global     = TRUE
    runRegExpReplace = regEx.Replace(haystack, newtext)
End Function

'// @param string Text to replace selected text
Private Function handleSelText(text)
    On Error Resume Next
    Set editor = newEditor()
    editor.assignActiveEditor
    If text = "" Then
        '// Get selected text
        handleSelText = editor.selText
        If handleSelText = "" Then
            '// No text was select. Get all text and select it.
            handleSelText  = editor.Text
            editor.command "ecSelectAll"
        End If
    Else
        '// Set selected text
        editor.selText text
    End If
End Function
 
Back to Top

assignEditorByIndex(index: integer): boolean

Assign editor window to object by editor index.

Example VBscript
Sub GetOpenFiles()
    On Error Resume Next
    Set tmpeditor = newEditor()
    Set outputlog = NewEditor()
    outputlog.AssignLog
    outputlog.selText(vbNewLine)
    i = 0
    Do While tmpeditor.assignEditorByIndex(i)
        FileName = tmpeditor.fileName
        '// assignEditorByIndex always return 1, hack to detrmine when all
        '// open editors have been handled.
        If FileName = LastFileName Then
            Exit Do
        End If
        LastFileName = FileName
        outputlog.selText(FileName & vbNewLine)
        i = i + 1
    Loop
    outputlog.selText("Number of open file: " & i & vbNewLine)
End Sub
 
Back to Top

assignEditorByName(file_name: string): boolean

Assign editor window to object by file name.

Back to Top

assignLog(): boolean

This function is obsolete and is replaced with logXXXXX() functions.

Example VBscript
'// Paste clipboard content to log
'// Requires PSPad 4.3.3 (2065)
Sub paste2Log
    Set outputlog = NewEditor
    With outputlog
        .AssignLog
        .selText(vbNewLine)
        .command "ecPaste"
    End With
End Sub
 
Back to Top

caretX(integer): integer

Sets/returns editor CaretX position.

Back to Top

caretY(integer): integer

Sets/returns editor CaretY position.

Back to Top

closeFile(): boolean

Closes file.

Back to Top

command(editor_command: string): boolean

Runs editor command processor command. Click here for a list of comands.

Back to Top

fileName(string): string

Sets/returns editor file name.

Example VBscript
Private Function GetFileName()
    On Error Resume Next
    Set editor = newEditor()
    editor.assignActiveEditor
    GetFileName = editor.fileName
End Function

Sub openFolder
    Set FS     = CreateObject("Scripting.FileSystemObject")
    Set Shell  = CreateObject("Shell.Application")
    Set File   = FS.GetFile(GetFileName())
    folderName = File.ParentFolder
    Shell.Explore folderName
End Sub
 
Back to Top

lineText(string): string

Replaces/returns content of active line.

Back to Top

linesCount(): integer

Returns editor lines count.

Back to Top

newFile([file_name: string]): boolean

Creates new file in PSPad. File name is optional.

Back to Top

openFile(file_name: string): boolean

Opens existing file in new editor window.

Back to Top

openFileFromFTP(name): boolean

Opens file using FTP.

Back to Top

printFile(Show dialog box: boolean): boolean

Print editor. Note: For text files only. Will not print Hex file

Back to Top

readOnly(status: boolean): boolean

Set or return current editor read only (R/O) status.

Back to Top

reloadFile(): boolean

Reload file.

Back to Top

saveFile(): boolean

Saves file.

Back to Top

saveFileAs(file_name: string): boolean

Saves file as.

Back to Top

saveFileToFTP(): boolean

Saves file to current FTP directory.

Back to Top

selText(string): string

Replaces/returns selected text from editor.

Back to Top

setBlockBegin(x: integer, y: integer): boolean

Sets begin of block selection.

Back to Top

setBlockEnd(x: integer, y: integer): boolean

Sets End of block selection.

Back to Top

blockBeginX(): integer

Returns block selection bounds, begin X.

Back to Top

blockBeginY(): integer

Returns block selection bounds, begin y.

Back to Top

blockEndX(): integer

Returns block selection bounds, end x.

Back to Top

blockEndY(): integer

Returns block selection bounds, end y.

Back to Top

selStart(integer): integer

Returns/sets selection start.

Back to Top

selLength(integer): integer

Returns/sets selection length.

Back to Top

selectionMode(value: string)

Sets selection mode - C:column, L:line, N:normal.

Back to Top

setCaretPos(x: integer, y: integer): boolean

Sets editor caret position. -1 in parameter mean no change coordinate.

Back to Top

text(value: string):string

Replaces/returns all editor text.

Back to Top

logClear()

Clears whole LOG window content.

Back to Top

logAddLine(test: string)

Adds new line into LOG.

Back to Top

logGetLine(index: integer): string

Returns line from LOG, identified by index parameter (numbered from 0).

Back to Top

logSetLine(index: integer, test: string)

Sets log line, identified by index.

Back to Top

logLinesCount(): Integer

Sets log line, identified by index.

Back to Top

projectSave(): long

Save current project. Always returns a value of 1.

Back to Top

projectFilesCount(): long

Number of files in current project.

Back to Top

projectFiles(index: long): string

File path including filename.

Example VBscript
Function listProjectFiles()
    data = ""
    For i = 0 To projectFilesCount - 1
        data = data & projectFiles(i) & vbNewLine
    Next
    listProjectFiles = data
End Function

 
Back to Top

projectFileName(): string

Project file path including filename.

Back to Top

ftpConnect(connection: string): Boolean

Connect to predefined FTP connection.

Back to Top

ftpDisconnect()

Disconnect FTP server.

Back to Top

ftpCommand(command: string)

Send command to FTP server, e.g.. "CWD \public\www".

Back to Top

ftpDownloadFile(ftp_name:string, local_name:string): boolean

Download file using FTP.

Back to Top

ftpUploadFile(local_name:string, ftp_name:string): boolean

Upload file using FTP.

Back to Top