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 |
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 |
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 |
Command | Description |
---|---|
projectSave | Save current project |
projectFilesCount | Number of files in current project |
projectFiles | File path including filename |
projectFileName | Project file path including filename |
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.
' 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
// 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");
}
def Init():
pspad.addMenuItem("Example function", "PySample sample", "beispiel")
pspad.addMenuItem("Version", "PySample sample", "version")
pspad.addMenuItem("Selection", "PySample sample", "selection")
echo(text: string): void
Information box with text and button OK.
echo "Hello World!"
echo("Hello World!")
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 Topsleep(ms: integer): void
Stops script execution for number of miliseconds.
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
pspadVersion(): string
Returns PSPad version.
echo "PSPad version : " & pspadVersion()
echo("PSPad version : " + pspadVersion());
def version():
version = 'pspad version: %s\n' % pspad.pspadVersion()
pspad.echo(version)
getVarValue(variable: string)[, filename: string]:string
Returns any PSPad variable. Second parameter is optional, is used fo filename related variables.
test = getVarValue("%UserName%")
echo(test)
moduleExists(name: string):boolean
Returns version of module, if module doesn't exists, returns empty string.
Back to TopmoduleVersion(name: string):string
Returns file name of module, if module doesn't exists, returns empty string.
echo "Module version: " & moduleVersion(module_name)
echo("Module version: " + moduleVersion(module_name));
def version():
version = 'module version: %s' % pspad.moduleVersion('PySample')
pspad.echo(version)
moduleFileName(file_name: string): boolean
Returns module filename include last backslash.
Back to TopmodulePath():string
returns module file path include last backslash.
Back to TopcloseEditorByTitle(file_name: string): boolean
Closes editor by filename.
Back to TopcloseEditorByIndex(index: integer): boolean
Closes editor by index.
Back to TopcloseAllEditors(): void
Closes all editor windows.
Back to TopnewEditor(): object
Creates new object for editor handling.
Set editor = newEditor()
editor.assignActiveEditor
handleSelText = editor.selText
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
editorsCount():integer
Number of currently open editors.
Back to TopsetClipboardText(text: string)
Stores text into clipboard.
Back to TopgetClipboardText(): string
Returns text from clipboad.
Back to ToprunPSPadAction(action: string)
Runs any PSPad action. Click here for a list of comands.
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
activate(): boolean
Set focus to editor. Return a value of True/1 on success
Back to TopappendText(string): boolean
Appends text to editor end.
Back to TopassignActiveEditor(): boolean
Assign active editor window into object and show it.
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
assignEditorByIndex(index: integer): boolean
Assign editor window to object by editor index.
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
assignEditorByName(file_name: string): boolean
Assign editor window to object by file name.
Back to TopassignLog(): boolean
This function is obsolete and is replaced with logXXXXX() functions.
'// 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
caretX(integer): integer
Sets/returns editor CaretX position.
Back to TopcaretY(integer): integer
Sets/returns editor CaretY position.
Back to TopcloseFile(): boolean
Closes file.
Back to Topcommand(editor_command: string): boolean
Runs editor command processor command. Click here for a list of comands.
Back to TopfileName(string): string
Sets/returns editor file name.
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
lineText(string): string
Replaces/returns content of active line.
Back to ToplinesCount(): integer
Returns editor lines count.
Back to TopnewFile([file_name: string]): boolean
Creates new file in PSPad. File name is optional.
Back to TopopenFile(file_name: string): boolean
Opens existing file in new editor window.
Back to TopopenFileFromFTP(name): boolean
Opens file using FTP.
Back to TopprintFile(Show dialog box: boolean): boolean
Print editor. Note: For text files only. Will not print Hex file
Back to TopreadOnly(status: boolean): boolean
Set or return current editor read only (R/O) status.
Back to TopreloadFile(): boolean
Reload file.
Back to TopsaveFile(): boolean
Saves file.
Back to TopsaveFileAs(file_name: string): boolean
Saves file as.
Back to TopsaveFileToFTP(): boolean
Saves file to current FTP directory.
Back to TopselText(string): string
Replaces/returns selected text from editor.
Back to TopsetBlockBegin(x: integer, y: integer): boolean
Sets begin of block selection.
Back to TopsetBlockEnd(x: integer, y: integer): boolean
Sets End of block selection.
Back to TopblockBeginX(): integer
Returns block selection bounds, begin X.
Back to TopblockBeginY(): integer
Returns block selection bounds, begin y.
Back to TopblockEndX(): integer
Returns block selection bounds, end x.
Back to TopblockEndY(): integer
Returns block selection bounds, end y.
Back to TopselStart(integer): integer
Returns/sets selection start.
Back to TopselLength(integer): integer
Returns/sets selection length.
Back to TopselectionMode(value: string)
Sets selection mode - C:column, L:line, N:normal.
Back to TopsetCaretPos(x: integer, y: integer): boolean
Sets editor caret position. -1 in parameter mean no change coordinate.
Back to Toptext(value: string):string
Replaces/returns all editor text.
Back to ToplogClear()
Clears whole LOG window content.
Back to ToplogAddLine(test: string)
Adds new line into LOG.
Back to ToplogGetLine(index: integer): string
Returns line from LOG, identified by index parameter (numbered from 0).
Back to ToplogSetLine(index: integer, test: string)
Sets log line, identified by index.
Back to ToplogLinesCount(): Integer
Sets log line, identified by index.
Back to TopprojectSave(): long
Save current project. Always returns a value of 1.
Back to TopprojectFilesCount(): long
Number of files in current project.
Back to TopprojectFiles(index: long): string
File path including filename.
Function listProjectFiles()
data = ""
For i = 0 To projectFilesCount - 1
data = data & projectFiles(i) & vbNewLine
Next
listProjectFiles = data
End Function
projectFileName(): string
Project file path including filename.
Back to TopftpConnect(connection: string): Boolean
Connect to predefined FTP connection.
Back to TopftpDisconnect()
Disconnect FTP server.
Back to TopftpCommand(command: string)
Send command to FTP server, e.g.. "CWD \public\www".
Back to TopftpDownloadFile(ftp_name:string, local_name:string): boolean
Download file using FTP.
Back to TopftpUploadFile(local_name:string, ftp_name:string): boolean
Upload file using FTP.
Back to Top