Last modified 2006/10/16, 1 New, 0 Updated

General

Keystrokes Sending

File

Variable Manipulation

Windows

Text Processing

Clipboard

Windows Processes

Forms and Menus

Internet

Registry

 

Note: All macro samples are sorted by categories.

 

   
 
 Start Notepad and Type Text in There  
 
Sample Id: KEY0001
Description:
The macro starts Notepad and when its window is opened on the screen, a text is typed in it (keystrokes are sent). There are two versions of the macro.  The first one is more complicated, however, reliable in all circumstances and the second one is really simple, working on most computers but not so bullet proof as the first one.
Author: Pitrinec, support@pitrinec.com

Commented macro code:

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored
<cmds>

<#> Start notepad...
<execappex>("notepad.exe","","",0,0)

<#>... and wait until it is loaded
<waitfor>("WIN","OPEN","mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",5,0)

<#> Make Notepad window active (so that it can receive keyboard keys)...
<actwin>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0,0,"no")

<#> and make sure the Notepad window is active
<if_win>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ","ACT",0)

   <#> all the text after 'keys' command is executed and is sent as a set of
   <#> keystrokes to the active window (Notepad, in our case)...

   <keys>Hello Notepad!<cmds><#> ...and use 'cmds' command again

<#> Endo of 'if' statemnt
<endif>

<#> End of the macro

Does this look too complicated for such a simple task? Look at this simplified (and less reliable) version:

<#> Start of the macro
<#> Start notepad and send keystrokes to it
<execappex>("notepad.exe","","",0,0)Hello Notepad!

<#> End of the macro
 

   
 
 Activate or Run Notepad 
 
Sample Id: WIN0001
Description:
Activate Notepad window if Notepad is running or start it if it is not running yet.
Author: Pitrinec, support@pitrinec.com

Commented macro code:

<#> Start of the macro
<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>

<#> Do not automatically display error message, the error will be handled in
<#> the macro directly

<me_error_nodisplay>

<#> Activate Notepad window defined by the window name (Notepad)
<actwin>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0,0,"no")

<#> Let's check _vErr system variable for an error...
<if_str>("_vErr!=NO")

   <#>The Notepad window probably does not exist yet so we have to start notepad.exe
   <#> Clear the error detected since it is handled now
   <me_error_clear>

  
<#> Start notepad.exe
   <execappex>("Notepad.exe","","",0,0)

<endif>

<#> Turn on automatic error display
<me_error_display>

<#> End of the macro

 

 
 
 Add prefix and postfix text to each line in text file  
 
Sample Id: KEY0002
Description:
This sample adds prefix and postfix text to each line in a selected text file. Open, load, modify and save text.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>

<#> Add Form Items-input file

<form_item>("f1","Input file:","EDIT_FILE","*.txt","vInputFile")
<#> Add Form Items-output file

<form_item>("f1","Output file:","EDIT_FILE","%_vFolder_Temp%\output.txt","vOutputFile")
<#> Add Form Items-prefix for each line

<form_item>("f1","Prefix:","EDIT",">>>","vPrefix")
<#> Add Form Items-postfix for each line

<form_item>("f1","Postfix:","EDIT","<<<","vPostfix")
<#>  Show this form

<form_show>("f1","Form","shell32.dll",0,,0)
<#> Is not last action (Form Show) cancelled? If Yes, then exit macro...

<if_str>("_vCanceled==1")<exitmacro><endif>

<#> Open text file for loading Data From File To Variable.

<data_load>("vbTemp_FileText","vInputFile","")
<#> Open file for saving text to file.

<data_save>("","vOutputFile","")
<#> If an error not occurs

<if_str>("_vErr==NO")
   <#> How many lines is in file?

   <var_oper>(vbTemp_NumOfLines,"vbTemp_FileText",TEXT_GET_NUMOFLINES,"","", "0")
   <#> Begin Loop 

   <begloop>(vbTemp_NumOfLines)
   
      <#> Assign to variable v100 value _vLoopCounter/100

      <varset>("v100=EXPR(%_vLoopCounter%/100)","")
      <#> Is _vLoopCounter = EXPR(100*%v100%)")

      <if_num>("_vLoopCounter == EXPR(100*%v100%)")
         <#> Close Message

         <msgoff>
         <#> Show message window

         <msg>(32,32,"%_vLoopCounter% lines of %vbTemp_NumOfLines% processed.","Processing",0)
       <#> End If_num...

      <endif>

      <#> Assign Text line (number _vLoopCounter) to variable vbTemp_LineText

      <var_oper>(vbTemp_LineText,"vbTemp_FileText",TEXT_GET_LINE,"_vLoopCounter","", "0")

      <#> Add prefix

      <var_oper>(vbTemp_LineText,"%vbTemp_LineText%",STR_INSERT,"0","%vPrefix%", "0")
      <#> Add postfix

      <var_oper>(vbTemp_LineText,"%vbTemp_LineText%",STR_APPEND,"%vPostfix%%_vKeyReturn%","", "0")

      <#> Save lext lin in to file

      <data_save>("vbTemp_LineText","vOutputFile","A")
  
   <#> Endloop of vbTemp_NumOfLines

   <endloop>

<else>
   <#> Show error message

   <msg>(-100,-100,"_vError","File Error",1)
<endif>

<#> Show dialog 

<msg>(-100,-100,"Do you want to open output file now?","Message",2)
<#> If last button Yes?

<if_str>("_vMsgButton==YES")
   <#> Open Output file 

   <fileopen>("%vOutputFile%",0)
<endif>
<#> End of the macro

 

 
 
 Close all Notepad Windows 
 
Sample Id: WIN0002
Description:
This macro will close all opened Notepad windows. 
Author: Pitrinec, support@pitrinec.com

Commented macro code:

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored
<cmds>
<#> Do Not Display Errors during macro execution  

<me_error_nodisplay>
<#> Name of the point to jump to  

<label>("CloseNext")
<#> Try to close Notepad window  

<winclose>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0)
<#> If success   

<if_str>("_vErr==NO")
   <#> Try to close next Notepad window  

   <goto>("CloseNext")
<else>
   <#> No Notepad window closed, clear error messages  

   <me_error_clear>
<endif>
<#> Enable showing error messages  

<me_error_display>

<#> End of the macro

 

 
 
 Convert clipboard text to uppercase 
 

Sample Id: CLI0001
Description: 
Assign data to variable, testing if these data are text, convert to uppercase, put converted data in to clipboard. 
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Assign clipboard data to variable vClipboardText

<var_oper>(vClipboardText,"",GET_TEXT_FROM_CLIPBOARD,"","", "0")
<#> Are data text?

<if_str>("vClipboardText!=_vStrEmpty")
  
<#> Convert data to uppercase

   <var_oper>(vClipboardText,"%vClipboardText%",STR_UPPER,"","", "0")
  
<#> put data back to clipboard

   <clpput>("vClipboardText")
<else>
  
<#> Clipboard is empty, or data are not text (picture...).

   <msg>(-100,-100,"Clipboard is empty.","Message",1)
<endif>

<#> End of the macro

 
 
 Detects if notepad.exe is running and kills it on users request 
 

Sample Id: PRO0001
Description: 
This macro will detects if application (Notepad) is running and will kill it on request.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Find notepad.exe in running processech

<if_process>(notepad.exe,EXIST)
  
<#> Ask for killing if running

   <msg>(-100,-100,"Notepad.exe is running. Do you want to kill it?","Message",2)
  
<#> Is last answer YES?

   <if_str>("_vMsgButton==YES")
      
<#> kill process   

      <process_kill>(notepad.exe)
   <endif>
<else>
  
<#> No process notepad.exe found, show message

   <msg>(-100,-100,"Notepad.exe is not running.","Message",1)
<endif>

<#> End of the macro

 
 
 Filter formatted text out of clipboard - leave only unformatted text in clipboard 
 

Sample Id: CLI0002
Description: 
The sample removes all formatting from the clipboard data (MS Word text copied for example) and leaves only plain text in the clipboard.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Assign only text data from clipdoard to variable vClipboardText

<var_oper>(vClipboardText,"",GET_TEXT_FROM_CLIPBOARD,"","", "0")
<#> Is any text in variable?

<if_str>("vClipboardText==_vStrEmpty")
   <#> No text in variable - show message. 

   <msg>(-100,-100,"There is NO text in clipboard. ","Message",1)
<else>
   <#> Yes, there is text, put it back in to clipboard. 

   <clpput>("%vClipboardText%")
<endif>

<#> End of the macro

 
 
 Variety text manipulation macros, all ready to use! 
 

Sample Id: TEX0005
Description: 

Set of text manipulation macros. For convenience and simplicity I assigned each group to numpad hotkeys. In order to easy assign the appropriate group to numpad keys the macro SwitchNumpad is used. It can be activated separately or by mouse macros TxtChg (with submenus) or TxtChg-Alternate (only main menu). These mouse macros can also be used to activate the text-manipulation macros in group TextManMacros. Above macros are located in mouse macro group TextManMouse. If in macro SwitchNumpad no macro is selected (ESC entered) the assignments to numpad keys are removed.

Currently there are two macro groups wich use numpad keys for activation:
 

  1. TextManMacros: Numpad keys 2, 7, 8, 9 are used to change the case of text parts, keys 5, 6 are used to move text parts. Object is the selected text or the word with the mose cursor if there is no selection. Key 5 toggles two adjacent characters (legastenic errors).
     
  2. ClipFix: Numpad keys 1-9 are used to store text strings or paste text strings into applications to/from global variables. If there is a selction the selected text is saved, if there is no selection the saved text is pasted (from global variable or disk if the variable does not exist). Key 0 is used to save/load to/from disk and display all 9 variables.

If you dont want to use numpad keys, there is another group of macros (MultiClip) to provide for 9 text strings to save/paste. They simulate the windows standard Ctrl-C, Ctrl-X, Ctrl-V with Win-C, Win-X, Win-V and afterwards pressing 1-9. 0 again is used to activate load/save by key.

All strings are saved to global variables ga_clip[x]. They can be saved/loded to file clip[x] in folder %temp% (can be changed by user in macro text).


Author:
Robert Gabler, robert.gabler@eunet.at

 

Macro file to download: TextMan.4tw, valid for Macro ToolsWorks version 7.

 

 
 
 Generate a file name containing current date 
 

Sample Id: TEX0001
Description: 
The example generates a file name that consists of the current date.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Define form field for variable vOriginalFileName

<form_item>("f1","Original file name:","EDIT","MyFileName","vOriginalFileName")
<#> Define form field for variable vFileExtension

<form_item>("f1","File extension:","EDIT",".txt","vFileExtension")
<#> Show form

<form_show>("f1","File Name","shell32.dll",0,0,0)
<#> If last key was Esc or button Cancel pressed, exit...

<if_str>("_vCanceled == 1") <exitmacro> <endif>

<#> Else assign to variable vNewFileName value : vOriginalFileName-Year-Month-Day.txt
<varset>("vNewFileName=%vOriginalFileName%-%_vCurrDate_Year%-%_vCurrDate_MM%-%_vCurrDate_DD%%vFileExtension%","")
<#> Show new file name in message window

<msg>(-100,-100,"vNewFileName","Message",1)

<#> End of the macro

 
 
 Generate letter from information defined in form 
 

Sample Id: TEX0002
Description:
 Show input form for getting variables, starting Notepad, inserting text and variables.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> 
<#> Initialize and show form: field for variable vCustomerName
<form_item>("f1","Customer name:","EDIT","","vCustomerName")
<#> Field - ListBox - for variable vService

<form_item>("f1","Service:","LIST","UNIX Virtual Server|NT Virtual Server|UNIX Dedicated Server|NT Dedicated Server","vService")
<#> ListBox for variable vDiscount

<form_item>("f1","Discount (in %):","LIST","0|5|10|20|30|50","vDiscount")
<#> ListBox for var. vStaff

<form_item>("f1","Support staff:","LIST","John McSmith|Adrian Mane|Brigita Largo","vStaff")
<#> Show form f1

<form_show>("f1","Customer Requests Information About Service","shell32.dll",0)
<#> If last key Esc or button ancel pressed - exit macro

<if_str>("_vCanceled == 1") <exitmacro> <endif>
<#> Else start Notepad and make it active window
<execappex>("notepad.exe","","",0,0)
<#> Wait while program not opened...

<waitfor>("WIN","OPEN","mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",5,0)
<#> Activate Notepad window

<actwin>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0,0,"no")
<#> Is Notepad window active? 

<if_win>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ","ACT",0)
<#> Assign right value for vPrice
   <if_str>("vService==UNIX Virtual Server")
      <#> 

      <varset>("vPrice=99.95","")
   <endif>
   <#> 

   <if_str>("vService==NT Virtual Server")

      <#> 
      <varset>("vPrice=79.95","")
   <endif>
   <#> 

   <if_str>("vService==UNIX Dedicated Server")
      <#> 

      <varset>("vPrice=299.95","")
   <endif>
   <#> 

   <if_str>("vService==NT Dedicated Server")
      <#> 

      <varset>("vPrice=259.95","")
   <endif>
<#> 
<endif>

<#> Calculate variable vDiscountedPrice

<var_oper>(vDiscountedPrice,"%vPrice%-(%vPrice%*(%vDiscount%/100))",CALC_EXPRESSION,"2","", "0")

<#> Start writing letter here:
<keys>Dear <varout>("vCustomerName",0),

thank you very much for contacting us concerning our
web hosting services. Find below some facts about
the service you are interested in. We are glad we can 
offer you discounted price!


-------------------------------------------------------
<#> Send variable to Notepad

Customer: <varout>("vCustomerName",0)
<#> Send variable to Notepad

Service: <varout>("vService",0)
Bandwith: Unlimited
Price: <varout>("vPrice",0)/month
Discount: <varout>("vDiscount",0)%
Price after discount:<varout>("vDiscountedPrice",0)/month
-------------------------------------------------------

Feel free to contact us with any question any time.
<#> Send variable to Notepad
<varout>("vStaff",0)
The Service Company Support

<#> End of the macro

 
 
 Insert current date to file name (uses procedures) 
 

Sample Id: TEX0003
Description:
 Defining of procedures, labels, loops. Work with Date, file names, string.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Start definition of procedure GetDateString  with parameter parDateString 
<proc_def_begin>(GetDateString, "&parDateString&")
<#> Assign value to variable parDateString

<varset>("parDateString=-%_vCurrDate_Year%-%_vCurrDate_MM%-%_vCurrDate_DD%","")
<#> End of procedure

<proc_def_end>

<#> Start definition of procedure InsertDateToFileName with parameter parFileName
<proc_def_begin>(InsertDateToFileName, "&parFileName&")
<#> Call procedure GetDateString with param. lpvDateString

<proc_call>(GetDateString,"lpvDateString")
<#> Count to vbLnt length of string parFileName

<var_oper>(vbLnt,"%parFileName%",STR_LENGTH,"","", "0")
<#> Begin loop for var. vbLnt

<begloop>(vbLnt)
   <#> Performs selected operation on input variable

   <var_oper>(vbInx,"%vbLnt%-%_vLoopCounter%",CALC_EXPRESSION,"0","", "0")
   <#> Performs selected operation on input variable

   <var_oper>(vbChar,"%parFileName%",STR_GET_CHAR,"vbInx","", "0")
   <#> If found char "."

   <if_str>("vbChar==.")
      <#> Insert var. lpvDateString before "."

      <var_oper>(parFileName,"%parFileName%",STR_INSERT,"vbInx","%lpvDateString%", "0")

      <#> Go to label lbl_b_End
      <goto>("lbl_b_End")
   <endif>
<endloop>
<#> Append var. lpvDateString at the end of variable parFileName ( char "." not found ...)

<var_oper>(parFileName,"%parFileName%",STR_APPEND,"%lpvDateString%","", "0")
<#> Label lbl_b_End

<label>("lbl_b_End")
<#> End of procedure

<proc_def_end>

 

<#> Start of macro
<var_oper>(vFile,"",SELECT_FILE," ","", "0")
<#> If last key ESC or button Cancel

<if_str>("_vCanceled == 1") <exitmacro> <endif>
<#> Else call procedure InsertDateToFileName with parameter vFile

<proc_call>(InsertDateToFileName,"vFile")
<#> Show message with new file name...

<msg>(-100,-100,"vFile","Message",1)\

<#> End of the macro

 
 
 Insert time & date in Notepad 
 

Sample Id: VAR0001
Description:
 Starts Notepad and then inserts time & date
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Start Notepad and make it active window
<execappex>("notepad.exe","","",0,0)
<#> Wait for starting Notepad 5 seconds

<waitfor>("WIN","OPEN","mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",5,0)
<#> Activate Notepad window

<actwin>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0,0,"no")
<#> Is Notepad window active?

<if_win>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ","ACT",0)

   <#> Yes, insert time & date here:
  
<keys>Current time:<time>(0,1,1,1,1)
Current date:
<date>(9,"/",1,1,0)

Current date formatted a diferent way using a variable and system variables: <cmds>
   <#> Put current date to variable vDate

   <varset>("vDate=<%_vCurrDate_DD%><%_vCurrDate_MM%><%_vCurrDate_Year%>","")
   <#> Put variable vDate to Notepad

   <varout>("vDate",0)
<endif>

<#> End of the macro

 
 
 Is connected to internet 
 

Sample Id: INT0001
Description: 
Test, if computer is connected to internet - special variable "_vIsConnectedToInternet"
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Test of variable _vIsConnectedToInternet

<if_str>("_vIsConnectedToInternet==YES")
   <#> Yes, show message

   <msg>(-100,-100,"Computer is connected to internet.","Message",1)
<else>
   <#> No, show message

   <msg>(-100,-100,"Computer is NOT connected to internet.","Message",1)
<endif>

<#> End of the macro

 
 
 List files from selected directory 
 

Sample Id: FIL0001
Description:
 Select folder, count files in this folder, open Notepad and write names of files in to Notepad.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Get folder for counting files...
<var_oper>(gm_vbiDirectory,"",SELECT_FOLDER,"","", "0")
<#> If no folder selected, exit this macro. 

<if_str>("_vCanceled==1")<exitmacro><endif>
<#> Get list of files in folder and count these files
<file_enum>("%gm_vbiDirectory%\*.*",2,vTemp_Files,vTemp_NumOfFiles)
<#> If there is no file in selected folder
<if_num>("vTemp_NumOfFiles==0")
   <#> Show message 

   <msg>(-100,-100,"No files found in selected directory.","Message",1)
   <#> exit this macro

   <exitmacro>
<endif>

<#> Start Notepad and make it active window
<execappex>("notepad.exe","","",0,0)
<waitfor>("WIN","OPEN","mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",5,0)
<actwin>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0,0,"no")
<if_win>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ","ACT",0)

   <#> Write each file name to new line in Notepad
   <begloop>(vTemp_NumOfFiles)
      <varout>("vTemp_Files[_vLoopCounter0]",0)
      <newline>
   <endloop>
<endif>

<#> End of the macro

 
 
 Math expressions calculator 
 

Sample Id: FOR0001
Description:
 Show input box for math expression and calc it. Do it while key Esc or button Cancel not pressed.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Define input field for math expression
<form_item>("f1","Math. Expression:","EDIT","","vExpression")
<#> Define text label under input field - example 

<form_item>("f1","Example: 1+(3/2-3.212)^2","TEXT","","")

<#> Program label "Show"
<label>("Show")

<#> Show form with input field
<form_show>("f1","Mathematical Expression Calculator","shell32.dll",12)
<#> Esc or Cancel pressed - then exit macro

<if_str>("_vCanceled == 1") <exitmacro> <endif>

<#> Calculate entered expression
<var_oper>(vResult,"%vExpression%",CALC_EXPRESSION,"4","", "0")
<#> Show result 

<msg>(-100,-100,"vResult","Result:",1)

<#> Go to program label "Show"
<goto>("Show")

<#> End of the macro

 
 
 Parse full file path to components 
 

Sample Id: VAR0002
Description:
 This sample breaks full file path into pieces.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Show input form for variable vInputFile 
<var_oper>(vInputFile,"",SELECT_FILE,"Select File","", "0")
<#> Esc or Cancel pressed - then exit macro

<if_str>("_vCanceled==1")<exitmacro><endif>
<#> Parse var. vInputFile to components delimited by ":\"
<var_parse>("vInputFile",":\","",vFilePathComponents,vNumOfFilePathComponents)
<var_oper>(vNumOfFilePathComponents,"%vNumOfFilePathComponents%-1",CALC_EXPRESSION,"0","", "0")

<#> File Name:
<varset>("vOutput_FileName=vFilePathComponents[vNumOfFilePathComponents]","")
<var_oper>(vNumOfFilePathComponents,"%vNumOfFilePathComponents%-1",CALC_EXPRESSION,"0","", "0")

<#> Drive Letter:
<varset>("vOutput_Drive=vFilePathComponents[0]","")
<var_oper>(vTemp,"%vOutput_Drive%",STR_LENGTH,"","", "0")
<if_num>("vTemp>1")
   <#> This is network path like \\server\directory\,,,\
   <varset>("vOutput_Drive=\\%vOutput_Drive%\","")
<else>
   <#> This is local path like c:\directory\,,,\
   <varset>("vOutput_Drive=%vOutput_Drive%:\","")
<endif>

<#> Directory:
<varset>("vOutput_Directory=_vStrEmpty","")

<begloop>(vNumOfFilePathComponents)
   <var_oper>(vOutput_Directory,"%vOutput_Directory%",STR_APPEND,"%vFilePathComponents[_vLoopCounter]%\","", "0")
<endloop>

<msg>(-100,-100,"Original file: %vInputFile%

Drive: %vOutput_Drive%
Directory path: %vOutput_Directory%
File name: %vOutput_FileName%","Message",1)

<#> End of the macro

 
 
 Retrieve e-mail addresses from a text file 
 

Sample Id: TEX0004
Description: 
Opening file, operation with variables, showing message.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>

<#> Show input form for variable vInputFile
<msg>(100,100,"Select text file containing e-mail addresses to retrieve.","Message",0)
<var_oper>(vbFilePath_Input,"*.txt",SELECT_FILE,"Select File","", "0")
<#> Esc or Cancel pressed - then exit macro

<if_str>("_vCanceled==1")<exitmacro><endif>

<#> Close message window

<msgoff>

<#> Store 0 to variable vNumOfEmailAddresses 
<varset>("vNumOfEmailAddresses=0","")
<#> Load text file to variable vbTemp_FileText

<data_load>("vbTemp_FileText","vbFilePath_Input","")
<#> Is file loaded? No error?

<if_str>("_vErr==NO")

   <#> Count number of words in text
   <var_oper>(vNumOfWords,"%vbTemp_FileText%",TEXT_GET_NUMOFWORDS,"2",".", "0")
   <#> For each word in text do...

   <begloop>(vNumOfWords)

      <#> Get one word
      <var_oper>(vWord,"%vbTemp_FileText%",TEXT_GET_WORD,"%_vLoopCounter%",".", "0")
      <#> Compare, if in word is letter "@"

      <if_str>("vWord ~= @")

         <#> <#> Compare, if in word is letter "."

         <if_str>("vWord ~=.")
             <#> If yes, show message with e-mail address.

             <msg>(-100,-100,"INSTEAD OF THIS MESSAGE, YOU CAN DO YOUR OWN E-MAIL ADDRESS PROCESSING HERE.
            E-mail address found: %vWord%","E-mail Address Retrieved",1)
         <endif>
      <endif>
   <endloop>

<else>
   <#> Show error message

   <msg>(-100,-100,"_vError","File Error",1)
<endif>
<if_num>("vNumOfEmailAddresses==0")
   <#> Show message - "No e-mail address found in the file." 

   <msg>(-100,-100,"No e-mail address found in the file.","File Error",1)
<endif>

<#> End of the macro

 
 
 Run context menu command 
 

Sample Id: GEN0001
Description:
 Shows properties dialog box of "C:\" drive using "run context menu" command
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<run_ctxcommand>("c:\",Properties,0,0)<wx>(5000)

<#> End of the macro

 
 
 Select file and open it in Notepad 
 

Sample Id: FIL0003
Description: 
Select file and open it in Notepad. 
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds> 
<#> Get file to open

<var_oper>(vFile,"",SELECT_FILE,"","", "0")
<#> Esc or Cancel pressed - then exit macro

<if_str>("_vCanceled==1")<exitmacro><endif>
<#> Run Notepad and open file vFile

<execappex>("notepad.exe","vFile","",0,0)

<#> End of the macro

 
 
 Show menu of opened window and activate selected 
 

Sample Id: FOR0002
Description: Manipulating with variables, counting opened windows-applications, creating menu and selecting window-application.

Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Enumerate all visible and store number in to variable vNumOfWindows
<win_enumerate>(vWindow,vNumOfWindows,0)
<#> If is any visible window...
<if_num>("vNumOfWindows>0")
   <#> For all window  
   <begloop>(vNumOfWindows)
      <#> If current window caption is not empty
      <if_str>("vWindow[_vLoopCounter0]!=_vStrEmpty")
         <#> Add caption of window (application) in to menu

         <menu_additem>("vWindow[_vLoopCounter0]")
      <endif>
   <endloop>
   <#> Show menu with list of opned windows-applications 
   <menu_show>(-1,-1,vWindowSelected,1,1)
   <#> If any item of menu selected

   <if_str>("vWindowSelected!=NO")
      <#> Activate selected window-application 
      <actwin>("vWindowSelected",0,0,"no")
   <endif>
<endif>
<#> End of the macro

 
 
 Show registry subkeys 
 

Sample Id: 
Description:
 Read registry keys, start Notepad and write registry keys in to Notepad
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>

<#> Read registry keys in to array vKey[]
<reg_enumsubkeys>("HKEY_CURRENT_USER\Software","vKey","vNumOfKeys")
<#> If no key
<if_num>("vNumOfKeys==0")
   <#> Show message

   <msg>(-100,-100,"No keys found under HKEY_CURRENT_USER\Software.","Message",1) 

   <#> Exit macro

   <exitmacro>
<endif>

<#> Start Notepad and make it active window
<execappex>("notepad.exe","","",0,0)
<#> Wait while Notepad not opened

<waitfor>("WIN","OPEN","mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",5,0)
<#> Activate Notepad window

<actwin>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0,0,"no")

<#> If Notepad window is active - on top
<if_win>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ","ACT",0)
   <#> For each line in array vKey[] 
   <begloop>(vNumOfKeys)
      <#> Write current line of array vKey[] in to Notepad

      <varout>("vKey[_vLoopCounter0]",0)
      <#> Create new line (like Enter)

      <newline>
   <endloop>
<endif>

<#> End of the macro

 
 
 Shows how to use menus 
 

Sample Id: FOR0003
Description:
 How to create menu (submenu), show it and get result of selecting item of menu.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>

<#> Show message 

<msg>(100,100,"What color do you like?","Message",0)
<#> Add items to menu and submenu
<menu_additem>("Red")
<menu_additem>("Blue")
<menu_additem>("White")
<menu_additem>("---")
<menu_additem>(".Other")
<menu_additem>(".Green")
<menu_additem>(".Black")
<menu_additem>(".Yellow")
<menu_additem>("..Yet another")
<menu_additem>("..Tell me what?")
<menu_additem>(".")
<menu_additem>(".")
<menu_additem>("---")
<menu_additem>("I do not like colors")
<#> Show menu at position x,y (current position of mouse pointer -1,-1)
<menu_show>(-1,-1,vSelectedItem,1,0)

<msgoff>

<#> Remove leading . characters in a case the selected item is from submenu
<var_oper>(vSelectedItem,"%vSelectedItem%",STR_TRIMLEFT,".","", "0")

<#> Show message with selected menu item
<msg>(-100,-100,"You have selected: %vSelectedItem%","Message",1)

<#> End of the macro

 
 
 Simple form example 
 

Sample Id: FOR0004
Description:
 How to create simple input form and how to show variables in message box.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Define Combo box with Item1-5, variable vItem
<form_item>("f1","Items:","LIST","Item1|Item2|Item3|Item4|Item5","vItem")
<#> Define Edit box (text) for variable vame

<form_item>("f1","Your name:","EDIT","","vName")
<#> Define Check box for variable vLikeIt 

<form_item>("f1","I like it!","CHECK","YES","vLikeIt")
<#> Write only info text (label)

<form_item>("f1","This is just a sample.","TEXT","","")

<#> Show form with defined controls
<form_show>("f1","Sample Form","shell32.dll",2)
<#> If Esc or Cancel pressed, exit macro

<if_str>("_vCanceled == 1") <exitmacro> <endif>

<#> Show entered variables
<msg>(-100,-100,"In the form you have selected:

Item: %vItem%
Your name: %vName%
I like it: %vLikeIt%
","Form Results",1)

<#> End of the macro

 
 
 Simple FTP file download 
 

Sample Id: INT0002
Description: 

Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Set file name, where will be saved downloaded file

<varset>("vLocalFile=%_vFolder_Temp%hello.txt","")
<#> Download file to local file from "ftp://pitrinec.com/pub/hello.txt" with user name "anonymous" 

<ftp_getfile>("vLocalFile","ftp://pitrinec.com/pub/hello.txt","anonymous","")
<#> Any error ?

<if_str>("_vErr==NO")
   <#> No error, show message...

   <msg>(-100,-100,"The file was downloaded OK. It will be shown now.","Message",1)
   <#> and show content of downloaded file in Notepad

   <execappex>("notepad.exe","vLocalFile","",0,0)

<endif>

<#> End of the macro

 
 
 Start Notepad and type text in it - safe way 
 

Sample Id: KEY0003
Description:
 Start Notepad, wait while not loaded, activate Notepad window and send keys to Notepad.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>
<#> Start Notepad

<execappex>("notepad.exe","","",0,0)
<#> Wait until Notepad is loaded
<waitfor>("WIN","OPEN","mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",5,0)
<#> Make Notepad window active
<actwin>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ",0,0,"no")
<#> Make sure the Notepad window is active
<if_win>("mw[[ ]] mc[[ Notepad ]] cw[[ ]] cc[[ ]] ","ACT",0)
   <#> Send keys (text) to Notepad (active window)
  
<keys>Hello Notepad!<cmds> 
<endif>

<#> End of the macro

 
 
 Tests if clipboard contains text 
 

Sample Id: CLI0003
Description: 
Assigning content of clipboard (only text) and and controlling, if clipboard is not empty.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>

<#> Assign only text from clipboard to variable vClipboardText
<var_oper>(vClipboardText,"",GET_TEXT_FROM_CLIPBOARD,"","", "0")
<#> Is any text in variable vClipboardText

<if_str>("vClipboardText==_vStrEmpty")
   <#> If no, show message

   <msg>(-100,-100,"There is NO text in clipboard. ","Message",1)
<else>
   <#> If yes, show message with content of clipboard

   <msg>(-100,-100,"There is this text in clipboard:
   %vClipboardText%","Message",1)
<endif>

<#> End of the macro

 
 
 Fill WEB form 
 

Sample Id: FOR0005
Description: 
Start default WEB browser, navigate to sample macro page, wait for loading page, fill some fields.
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

 

<#> Sample macro for Microsoft Internet Explorer: 
<#> This macro fill fields in WEB form
<cmds>
<#> Start default internet browser
<wwwopen>("http://www.pitrinec.com/samples/macros/fillform/index.htm",0)
<#> Wait until page is loaded
<waitfor>("WEBPAGE","LOADED","http://www.pitrinec.com/samples/macros/fillform/index.htm",1,0)
<#> Wait 1000 miliseconds
<wx>(1000,1)
<#> Send keys (text) to fields (active window)
<keys>
<#> Sending Tabs to locate right field (in Firefox may be more or less...)
<tab><tab><tab><tab><tab><tab><tab>
<#> Fill field First name
Pavel
<#> Select next field
<tab>
<#>Fill field Last name
Pitrinec
<#> Select next field
<tab>
<#>Fill field Email 
pave@pitri.com 
<#> Select next field
<tab>
<#>Fill field WWW
www.pitrinec.com 
<#>Set focus to button Submit
<tab>
<
#> Send Enter to send data
<enter>
<#> End
of the macro

 
 
 Process lines in text file 
 

Sample Id: FIL0002
Description: 
The sample loads text file into variable and then takes line-by-line for further processing (shows in message box in our sample).
Author: Pitrinec, support@pitrinec.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

<cmds>

<#> Show input form for variable vInputFile 
<var_oper>(vFile,"",SELECT_FILE,"Select File","", "0")
<#> Esc or Cancel pressed - then exit macro

<if_str>("_vCanceled==1")<exitmacro><endif>

<#> Load data from file to variable

<data_load>("vbTemp_FileText","%vFile%","")
<#> If no error.

<if_str>("_vErr==NO")
   <#> Get number of lines 

   <var_oper>(vbTemp_NumOfLines,"vbTemp_FileText",TEXT_GET_NUMOFLINES,"","", "0")
   <#> Do for each line 

   <begloop>(vbTemp_NumOfLines)
      <#> Store current line in to variable vbLine

      <var_oper>(vbLine,"vbTemp_FileText",TEXT_GET_LINE,"_vLoopCounter","", "0")
      <#> Show message

      <msg>(-100,-100,"INSTEAD OF THIS MESSAGE, YOU CAN DO YOUR OWN FILE LINE PROCESSING.
      
      <#> Current line number

      Line number:
      %_vLoopCounter%
      

      <#> Current line content
      Line content:
      %vbLine%
      ","Message",1)

   <endloop>
<else>
   <#> Cannot load text file, show error  

   <msg>(100,100,"_vError","Error",1)
<endif>

<#> End of the macro

 
 
 
 Clipboard to infrared 
 

Sample Id: cli0004
Description: 
The macro instantly transfers text to a Palm or laptop via infrared connection. This is a 5 second process, if you want to copy an address or article for reading  in the park/train/bathroom/cafe/office/etc. The person simply copies the wanted text to their PC clipboard and activates the macro. For fastest use, run macro using a shortcut on your desktop, start menu or quick launch bar.

I use this with Perfect Keyboard 6.24, Windows XP Home, a Palm Zire 71 and a cheap USB infrared adaptor.

 

Author: Mark Major www.markmajor.com

 

Commented macro code:

 

<#> Start of the macro

<#> Only commands takes effect in the macro, new lines and other text is ignored

 <cmds>

<#>Clipboard2infrared by Mark Major www.markmajor.com

<#>Save text from clipboard to temporary text file

<data_save>("_vClpText","%_vFolder_Temp%\fromPCclipboard.txt","")

<#>Transfer file by infrared ftp

<execappex>("C:\WINDOWS\system32\irftp.exe","%_vFolder_Temp%\fromPCclipboard.txt /h","",0,0)

<#> End of the macro

 

 
 
 
 Share clipboard with local network users 
 

Sample Id: cli0005
Description: 
The macro allows multiple network users to share (maybe better said exchange) clipboard.  It is necessary that all the users have read/write access to a network folder ("\\Level32\documents\" folder in our example - this must be modified otherwise the sample will not work!!!).

 

Author: Mike Godin

 

Commented macro code:

 

<#> Start of the macro

<#>Transfer clipboard contents across network.
<#>

<cmds>
<form_item>("frmChooseCopyOrPaste","Transfer in which direction?","LIST","Local ---> Network|Network ---> Local","strChoice")
<form_show>("frmChooseCopyOrPaste","Network Clipboard","shell32.dll",0,400,1)
<if_str>("_vCanceled == 1")<exitmacro><endif>
<if_str>("strChoice==Local ---> Network")
    <clpsave>("\\Level32\documents\Network Clipboard.clx") <#> Folder must be modified - put your own here
<else>
    <clpload>("\\Level32\documents\Network Clipboard.clx") <#> Folder must be modified - put your own here
<endif>
<#> End of the macro

 

 
 
 Set default printer (Windows98) 
 

Sample Id: win0003
Description: 
This macro will change default printer for Windows 98. 

 

Author: Robert Gabler

 

Commented macro code:

 

<#> Start of the macro

<cmds> <#>only nesessary if not in before code
<#>(you need it when formatting and commenting)

<reg_getvalue>("HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers","Default","printer")
<#>get default setting
<menu_additem>("==Default: %printer%==","") <#>start menu
<reg_enumsubkeys>("HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers","printers","nrprts")
<begloop>(nrprts)
   <menu_additem>("printers[_vLoopCounter0]","")
   <#>get all printers from registry
<endloop>
<menu_show>(100,100,printer,1,0) <#>select desired printer
<if_str>("printer==NO")
   <exitmacro> <#>no printer selected
<endif>
<#>====================Adjust Registry
<reg_setvalue>("HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers","Default","printer","0")
<#>set registry default printer
<#>====================Adjust win.ini

<data_load>("winini","d:\windows\win.ini","") <#>read win.ini
<var_parse>("winini","_vKeyReturn","",file,n) <#>separate lines
<var_oper>(index,"device=",ARRAY_FINDITEM_PARTIALMATCH_NOCASE,"0","file", "0")
<#>find "device=<printer>" line
<var_oper>(winini,"winini",STR_REPLACE,"file[index]","device=%printer%,", "0")
<#>replace line in file variable
<data_save>("winini","d:\windows\win.ini","") <#>writeback win.ini
<#> End of the macro

 

 
 Close Windows 
 

Sample Id: win0004
Description: 
The old version of the following macro first made an enumerate of all windows and then started closing. Sometimes this takes al little while. This version first tries to close the active window an avoids enumeration if not necessary. So it is faster.

 

Author: Robert Gabler

 

Commented macro code:

 

<#> Start of the macro

<cmds>
<#>close the first window found by enumerate. TaskBar and ProgramManager are skipped
<#>Holding down the trigger-key will continue closing windows until all are closed
<#>First test if active window can be closed
<proc_call>(winclose,"_vActiveWindow") close active window if user's
<win_enumerate>(win,num,0)
<begloop>(num)
   <proc_call>(winclose,"win[_vLoopCounter0]") close window if user's
<endloop>
<#>-------------PROCEDURES------------------------------------
<#>--The following procedure closes one window if possible----
<proc_def_begin>(winclose,"w")
   <if_str>("w!=") check for Task Bar
      <if_str>("w!=Program Manager") check for Program Manager
         <winclose>("w",0) not Program Manager, not Taskbar
<#>============here you can place window-specific action==============\
        
<if_str>("w~=WinOnCd") # This is only for WinOnCd
            <wx>(250,1)

            <varout>("n",0) # terminate with no save
         <endif>

<#>===================================================================/
         <exitmacro>
      <endif>
   <endif>
<proc_def_end>

<#> End of the macro