Author Topic: Example Script [Not working]: Script file template  (Read 2655 times)

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Example Script [Not working]: Script file template
« on: September 27, 2009, 07:38:21 pm »
Hi all.

To see what is possible by an script
and what is needed from the editor script engine
i post here some test scripts.

Please note that this scripts are NOT written for HippoEDIT right now
and that HippoEDIT didn't even have an scripting support implemented right now.
(script will be converted once HippoEDIT scripting support is implemented)

Hint:
* i am not an programmer,
* that script may not be well designed (mostly i am have less interest if my script works "fair to middling"
    to clean it up, because of i had to do other things is more important mostly)
* test my scripts with test files only
* i give no guarantee that your files are not deleted
   and that your computer will not gonna implode.

* the scripts are free to use and to modify. But please respect the copyright mentions inside the scripts.

(If YOU want to post scripts too, please add an disclaimer as mine too.
You could even use mine for non-working scripts)





Example Script [Not working]: Script template


I have always forgotten how to do things, since i need this every few weeks only.

So i have created an kind of template for new script files.

I think something like this should be delivered with HippoEDIT too for user assistance.


Code: [Select]
Const module_name  = "someName"   'this name must be unique !!!
Const module_ver   = "0.001a"     'version of your script
'==============================================================
' name "Init" is required, its called automatically during
' initialization to create menu items
Sub Init
'addMenuItem "Menu item", "Sub menu if wanted", "Name of Function to Call"
 addMenuItem "Click me to start the script", "Sub menu 1", "DoIt"
 addMenuItem "Main method", "VBscript sample", "Main"
 addMenuItem "&Open this script file to edit", MODULE_TITLE, "openThisScriptFile"
End Sub
'==============================================================
    Set WSH = Wscript.CreateObject("WScript.Shell")
    Set Shell  = CreateObject("Shell.Application")
    Set FSO = WScript.CreateObject("Scripting.FileSystemObject")

    vPSPadHome = getVarValue("%PSPath%")
    vPSPadScriptFolder = vPSPadHome  & "Script"
'==============================================================
sub Main                              'main procedure
Set editor = newEditor()  'new editor object             
    editor.assignActiveEditor() 'work with active document
vText = editor.selText() 'put selected text in variable vText

' here do something with this selected text
' e.g. splitt selected text into lines
' vArrayLines = Split(vText, vbCrlf)

' or ask something the user
vUserInput = InputBox("Input the value...", "My Title","1")
MsgBox "You entered: " & vUserInput,16,"Hello"
 
' collect all lines together
For i = 0 To UBound(vArrayLines)
 If Not i = UBound(vArrayLines) Then
  vStringList = vStringList & vArrayLines(i) & vbCrLf
 Else
  vStringList = vStringList & vArrayLines(i)
 End If
Next

'put the text back to the active document
editor.selText vStringList

Set editor = Nothing
End Sub 'Main
'==============================================================
Sub openThisScriptFile
    editor.openFile(moduleFileName(module_name))
End Sub
'<EOF>=========================================================

'==============================================================
' Script Language Reference ==> http://gogogadgetscott.info/pspad/functions.htm
' Macro commands ==> http://gogogadgetscott.info/pspad/macroprikaz.htm
' PSPad Scripts ==> http://www.pspad.com/de/pspad-extensions.php

Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
    • View Profile
Re: Example Script [Not working]: Script file template
« Reply #1 on: September 27, 2009, 07:47:24 pm »
And i had wrote an "Script helper" script for my own use
to automate some issues related to scripts:

Code: [Select]

' VB Script Document   
Const MODULE_NAME = "StS07PSPadScriptHelper"  'this name must be unique !!!
Const MODULE_VER = "0.1"
Const MODULE_TITLE = "PSPadScriptHelper"      'as displayed in PSPad menu
Sub Init
    addMenuItem "Open PSPad Script Folder in WinExplorer",      MODULE_TITLE, "openPSPadScriptFolder"
    addMenuItem "Open File from PSPad Script Folder",           MODULE_TITLE, "openFileFromPSPadScriptFolder"
    addMenuItem "Create new VBS file",                          MODULE_TITLE, "createNewFileInPSPadVBScriptFolder"
    addMenuItem "Open VBS help CHM",                            MODULE_TITLE, "openVBSHelp"
    addMenuItem "&Open this script file to edit",               MODULE_TITLE, "openThisScriptFile"
End Sub
'====================================================================='
    Set editor = newEditor()
    Set WSH = Wscript.CreateObject("WScript.Shell")
    Set Shell  = CreateObject("Shell.Application")
    Set fso = WScript.CreateObject("Scripting.FileSystemObject")
   
   
    PSPadHome = getVarValue("%PSPath%")
    PSPadScriptFolder = PSPadHome  & "Script"


    vYear = Year(Now)
    vMonth = Month(Now)
        If Len(vMonth) < 2 Then
          vMonth = "0" & vMonth
        End If
    vDay = Day(Now)
        If Len(vDay) < 2 Then
          vDay = "0" & vDay
        End If
    vHour = Hour(Now)
    vMin = Minute(Now)
    vSec = Second(Now)
        If Len(vSec) < 2 Then
         vSec = "0" & vSec
        End If       
    'vSep =  & "_" &
    vDate = vYear & "_" & vMonth & "_" & vDay & "_" & vHour & "_" & vMin & "_" & vSec
   


'====================================================================='
Sub openPSPadScriptFolder
    Shell.Explore PSPadScriptFolder
End Sub
'====================================================================='
Sub openFileFromPSPadScriptFolder
    WSH.SendKeys "^o"                  ' Ctrl+O => menu file\Open...
    Sleep(100)
        WSH.SendKeys "%n"              ' Alt+N in FileOpenDialog => dateiName:[   ] (see note below)
        Sleep(50)
          WSH.SendKeys PSPadScriptFolder       ' insert string from var 'PSPadScriptFolder'
          Sleep(50)
              WSH.SendKeys "%f"         ' Alt+F in FileOpenDialog => [√∂Ffnen]       (see note below)
'NOTE: modify the char 'n' and 'f' to the underlined char in your FileOpen-Dialog
End Sub
'====================================================================='   
Sub createNewFileInPSPadVBScriptFolder
Const vTempFile = "VBS-Temp-For-New-File.vbs"                            'the name of YOUR vbs script file
Set newTAB = newEditor()
  newTAB.openFile(PSPadScriptFolder & "\VBscript\" & vTempFile)          'moduleFileName("VBS-Temp-For-New-File"))
  newTAB.readOnly(false)
      SET oTempFolder = fso.GetFolder(wsh.ExpandEnvironmentStrings("%tmp%"))
      'msgbox oTempFolder & "\" & vDate & "_new.vbs" ,1
      newTAB.saveFileAs(oTempFolder & "\" & vDate & "_new.vbs")
       'WSH.SendKeys "{F12}"      'save as...
End Sub
'====================================================================='   
Sub openVBSHelp
WSH.run PSPadScriptFolder & "\VBSdocs.chm"
End Sub
'====================================================================='   

'====================================================================='   

'#########################################################

Sub openThisScriptFile
    editor.openFile(moduleFileName(module_name))
End Sub


 

Related Topics

  Subject / Started by Replies Last post
0 Replies
2219 Views
Last post September 27, 2009, 07:10:13 pm
by Stefan
0 Replies
1437 Views
Last post September 27, 2009, 07:18:54 pm
by Stefan
2 Replies
2010 Views
Last post September 27, 2009, 07:28:19 pm
by Stefan
1 Replies
2212 Views
Last post September 27, 2009, 07:58:59 pm
by Stefan
0 Replies
2060 Views
Last post June 05, 2010, 12:20:09 am
by Stefan