November 24, 2015

Finding HTML Attributes For Automating Web Sites

Filed under: Automation,Scripting,Web/Tech — Marcus Tettmar @ 1:00 pm

If you’re new to automating IE/websites with WebRecorder or the native Macro Scheduler IE functions you may be wondering how to determine which elements and attributes to use.

In this video I demonstrate how to use IE’s F12 key to invoke Developer Tools and use that to quickly find the elements we’re interested in and the attributes we need to use:

(You might want to click on the video toolbar to select a larger resolution size, view full screen or view on YouTube so that you can see the code).

November 11, 2015

Fix Unicode file with missing BOM

Filed under: Scripting — Marcus Tettmar @ 10:39 am

Macro Scheduler‘s ReadFile and ReadLn functions understand ANSI, UTF8 and Unicode files – as long as they have a valid BOM header.  But a client recently needed to read in a file with a missing BOM.  So we wrote a little bit of VBScript which reads the binary stream in, and then outputs a UTF8 encoded file.  

Here’s the code:

VBSTART
Sub UTFConvert(filename)
  Set fso = CreateObject("Scripting.FileSystemObject")
  txt = fso.OpenTextFile(filename, 1, False, -1).ReadAll
  Set stream = CreateObject("ADODB.Stream")
  stream.Open
  stream.Type     = 2 'text
  stream.Position = 0
  stream.Charset  = "utf-8"
  stream.WriteText txt
  stream.SaveToFile filename, 2
  stream.Close
End Sub
VBEND

//Convert it to UTF8
VBRun>UTFConvert,%SCRIPT_DIR%\data.txt

//Now we can read it :-)
ReadFile>%SCRIPT_DIR%\data.txt,theFileData

May 7, 2015

Self Documenting Macro Recorder Snapshots

Filed under: Announcements,General,Macro Recorder,Scripting — Marcus Tettmar @ 1:22 pm

Did you know that since Macro Scheduler 14.2 the Macro Recorder can store snapshots of windows and objects that you click on as you are recording?

This feature makes it easier to work out which bit of code does what as you can see the screenshots inside the script:

Note the thumbnail images in the script. To view a full sized version – as in the example above – double click on a thumbnail.

This feature is on by default but can be switched off before you record a macro by toggling the “Take Window Snapshot Images” option on the macro recorder settings dialog.

December 15, 2014

Happy Holidays

Filed under: General,Pointless but Fun,Scripting — Marcus Tettmar @ 11:22 am

Just a quick note to wish all our customers and readers of this blog good tidings for this festive season. Whether you celebrate this time of the year or not, we’ll be raising a glass to all of you.

Forum regular JRL has put together this snazzy little Macro Scheduler script. Paste it into a new macro and hit run for some festive cheer:

OnEvent>key_down,VK27,0,Quit
SRT>Quit
  SetControlText>Sparkler,TEdit,1,Complete
  WaitWindowClosed>Sparkler
  Wait>1
  DeleteFile>%temp_dir%Sparkler.scp
  Exit>0
END>Quit

DeleteFile>%temp_dir%Sparkler.scp
LabelToVar>SparkleScript,vScrData

Dialog>Dialog1
object Dialog1: TForm
  BorderStyle = bsNone
  Caption = 'Happy Holidays'
  ClientHeight = 330
  ClientWidth = 780
  Color = 111111
  Position = poScreenCenter
  object Panel3: TPanel
    Left = 0
    Top = 0
    Width = 780
    Height = 330
    BevelEdges = []
    BevelOuter = bvNone
    Caption = 'And a Happy New Year'
    Color = 111111
    Font.Charset = ANSI_CHARSET
    Font.Color = clRed
    Font.Height = -80
    Font.Name = 'Vladimir Script'
    Font.Style = []
    ParentFont = False
    Visible = False
  end
  object Panel2: TPanel
    Left = 0
    Top = 0
    Width = 780
    Height = 330
    BevelEdges = []
    BevelOuter = bvNone
    Caption = 'Merry Christmas'
    Color = 111111
    Font.Charset = ANSI_CHARSET
    Font.Color = clRed
    Font.Height = -96
    Font.Name = 'Old English Text MT'
    Font.Style = []
    ParentFont = False
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 780
    Height = 330
    BevelEdges = []
    BevelOuter = bvNone
    Caption = ''
    Color = 111111
  end
end
EndDialog>Dialog1

Show>Dialog1

ExecuteFile>%temp_dir%Sparkler.scp

Let>WIN_USEHANDLE=1
  GetWindowPos>Dialog1.handle,Dia1X,Dia1Y
Let>WIN_USEHANDLE=0
Add>Dia1Y,165
Let>StartY=Dia1Y
Let>YFlag=1
Wait>0.3

Let>kk=0
Repeat>kk
  Add>kk,4
  If>Dia1Y>{%StartY%+20}
    Let>YFlag=0
  EndIf
  If>Dia1Y<{%StartY%-20}
    Let>YFlag=1
  EndIf
  Add>Dia1X,4
  If>YFlag=1
    Add>Dia1Y,8
  Else
    Sub>Dia1Y,8
  EndIf
  Wait>0.025
  If>Dia1X>40
    SetControlText>Sparkler,TEdit,1,%Dia1X%;%Dia1Y%
  EndIf
  SetDialogProperty>Dialog1,Panel1,Left,kk
Until>kk>750

Timer>Begin

GetWindowPos>Sparkler,SparkX,SparkY

Label>Loop
If>{%Dia1X%<%SparkX%+150}
  Add>Dia1X,1
EndIf
If>Dia1Y>StartY
  Sub>Dia1Y,1
EndIf
If>Dia1YDia1Y,1
EndIf
SetControlText>Sparkler,TEdit,1,%Dia1X%;%Dia1Y%
Wait>0.01
Timer>Stop
If>{%Stop%-%Begin%>5000}
  GoSub>Fade
EndIf
Goto>Loop

SRT>Fade
  SetDialogProperty>Dialog1,,AlphaBlend,True
  Let>Fader=255
  Repeat>Fader
    Sub>Fader,5
    SetDialogProperty>Dialog1,,AlphaBlendValue,Fader
    Wait>0.1
  Until>Fader<0
  Let>Fader=255
  SetDialogProperty>Dialog1,Panel3,Visible,True
  SetDialogProperty>Dialog1,Panel2,Visible,False
  SetDialogProperty>Dialog1,,AlphaBlendValue,Fader
  Wait>3
  Timer>Begin
  GetScreenRes>ScreenX,ScreenY
  While>{%Stop%-%Begin%<10000}
    Timer>Stop
    Random>100,Pct
    Add>pct,1
    Let>Dia1X={round(%ScreenX%*(%pct%/100))}
    Random>100,Pct
    Add>pct,1
    Let>Dia1Y={round(%ScreenY%*(%pct%/100))}
    SetControlText>Sparkler,TEdit,1,%Dia1X%;%Dia1Y%
    Sub>Fader,5
    SetDialogProperty>Dialog1,,AlphaBlendValue,Fader
    Wait>0.2
  EndWhile
  SetControlText>Sparkler,TEdit,1,Complete
  WaitWindowClosed>Sparkler
  Wait>1
  DeleteFile>%temp_dir%Sparkler.scp
  
  Exit>0
END>Fade

/*
SparkleScript:
Let>size=200

OnEvent>key_down,vk27,0,Quit

SRT>Quit
  Exit>0
END>Quit

Dialog>Dialog2
object Dialog2: TForm
  BorderStyle = bsNone
  Caption = 'Sparkler'
  Color = 1
  TransparentColor = True
  TransparentColorValue = 1
  object Panel1: TPanel
    Left = 0
    Top = 0
    BevelOuter = bvNone
    Caption = 'Panel1'
    Color = 1
    TabOrder = 0
  end
  object Edit1: TEdit
    Text = '-1000;-1000'
    Visible = False
  end
end
EndDialog>Dialog2

Let>WIN_USEHANDLE=1
  MoveWindow>Dialog2.handle,-1000,-1000
Let>WIN_USEHANDLE=0
AddDialogHandler>Dialog2,,OnClose,Quit
SetDialogProperty>Dialog2,,ClientHeight,size
SetDialogProperty>Dialog2,,ClientWidth,size
SetDialogProperty>Dialog2,Panel1,Height,size
SetDialogProperty>Dialog2,Panel1,Width,size
SetDialogProperty>Dialog2,,AlphaBlend,True
SetDialogProperty>Dialog2,,AlphaBlendValue,0
Show>Dialog2

Let>halfSize={round(%size%/2)}
Let>85Per={round(%halfSize%*0.85)}
Let>15Per={round(%halfSize%*0.15)}
Let>ang2=0
Let>kk=0
SetDialogProperty>Dialog2,,AlphaBlendValue,255
Repeat>kk
  GetDialogProperty>Dialog2,Edit1,Text,vPos
  If>vPos=Complete
    Let>kk=-100
    Goto>Done
  EndIf
  Separate>vPos,;,Cur
  Sub>Cur_1,%halfSize%
  Sub>Cur_2,%halfSize%
  MoveWindow>Sparkler,Cur_1,Cur_2
  Add>kk,1
  Random>85Per,res
  Add>res,%15Per%
  Random>50,color
  Add>Color,45500
  Random>90,ang2
  Let>ang2=%ang2%*4
  GoSub>Angle,Dialog2,Panel1,ang2,%halfSize%,%halfSize%,%halfSize%,4,1
  Random>90,ang3
  Let>ang3=%ang3%*4
  GoSub>Angle,Dialog2,Panel1,ang3,%halfSize%,%halfSize%,%halfSize%,4,1
  Random>90,ang
  Let>ang=%ang%*4
  SetDialogProperty>Dialog2,Panel1,caption,space
  GoSub>Angle,Dialog2,Panel1,ang,%halfSize%,%halfSize%,res,2,color
  Label>Done
Until>kk<0

//Angle Usage:
//GoSub>Angle,Dialog,Object,Angle(in degrees),XStart,YStart,Length,PenSize,PenColor
//Requires Drawline subroutine
SRT>Angle
  Let>DegreeAngle=Angle_var_3
  Let>XStart=Angle_var_4
  Let>Ystart=Angle_var_5
  Let>LineLength=Angle_var_6
  Let>RadAngle={%DegreeAngle%*(pi/180)}
  Let>XEnd={trunc((cos(%RadAngle%))*%LineLength%)}
  Let>YEnd={trunc((sin(%RadAngle%))*%LineLength%)}
  Let>XEnd=%XEnd%+%XStart%
  Let>YEnd=%YEnd%+%YStart%
  GoSub>DrawLine,%Angle_var_1%.%Angle_var_2%.Handle,Angle_var_7,Angle_var_8,XStart,YStart,XEnd,YEnd
END>Angle

SRT>DrawLine
  LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
  LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
  LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
  Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
  LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
  LibFunc>gdi32,DeleteObject,DOres,Penres
  LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine
*/

Enjoy! 🙂

November 25, 2014

How to Trigger an Action if the Number of Connected Monitors Changes

Filed under: Automation,Scripting — Marcus Tettmar @ 9:57 am

Today I was asked if Macro Scheduler can trigger an action if the number of connected monitors changes. Yes, all we need is a way to determine how many monitors are connected to the system. VBScript is one way to do that. So then all we need is a loop that constantly checks this value. So we end up with something like this:

November 18, 2014

Tip: Remember – The Editor is a Debugger

Filed under: General,Scripting — Marcus Tettmar @ 9:11 am

When you run code in the Script Editor you are in fact running it inside a debugger.

This allows you to run code line by line or in chunks, and evaluate the values of your script variables in the watch list as you go.

By default – after a first install – the debugger always runs scripts from the top – the very first line. Just as would happen if you run the script some other way. From top to bottom.

But when you are debugging a script you often want to run a select number of lines or start debugging from a different line. So, to do this, you can disable “Run From Top”. This option is under the Tools menu.

When “Run From Top” is disabled the macro will start from whichever is the current line – i.e. whichever line currently has the cursor on it.

Recently in the forums two different people have had seemingly strange issues with scripts which turned out simply to be because they had this option turned off and weren’t running from the top. In both cases they were getting errors because some variables they were referencing hadn’t yet been created! The script had been started from a point after the variables were set.

So, when running in the editor, if you’ve previously disabled “Run From Top”, and you want to run the script as normal, either reset this option or put the cursor on the first line before running.

And if you see some seemingly strange behaviour which goes away when you run the script outside of the editor – it’s probably just because you haven’t run the script from the top!

For more info on how to use the debugger please see:

http://help.mjtnet.com/article/7-using-the-debugger
http://help.mjtnet.com/article/42-using-macro-schedulers-debugger-to-aid-script-creation

November 17, 2014

Relative Paths for Portable Macros – SCRIPT_DIR and BMP_DIR Explained

Filed under: General,Scripting — Marcus Tettmar @ 10:37 am

I’ve added an article to the knowledge base. Please read it here:

http://help.mjtnet.com/article/167-relative-paths-for-portable-macros-explaining-scriptdir-and-bmpdir

October 30, 2014

More SDK Examples – C++ and C##

Filed under: General,Scripting — Marcus Tettmar @ 2:12 pm

Following on from my last post with some examples of using the MacroScript SDK within Python I thought I’d post a simple C# and C++ example. These are the same examples that ship with the MacroScript SDK:

C#

C++

More info on the MacroScript SDK is here.

October 14, 2014

The Macro Scheduler MacroScript SDK in Python

Filed under: Automation,Scripting — Marcus Tettmar @ 2:19 pm

Did you know there was a Macro Scheduler SDK? It allows you to run Macro Scheduler code from right within your own apps. You can run and interact with MacroScript code within VB, C++, C#, Delphi, VBScript … or any other programming language which lets you use a COM object or Win native DLL.

It even works in Python. Here’s a small example which uses the screen image recognition functionality to find and click on the Windows Start button:

Another slightly more complex example which opens Notepad and types into it. It also demonstrates how you can call chunks of code at a time instead of all at once and set and get the value of script variables during execution. It also gets the result of the script set via MACRO_RESULT:

More information about the MacroScript SDK can be found here.

A number of customers have used the SDK to build macro-ing capabilities into their own products and/or create tighter integrations between their own software and automation routines using MacroScript.

If you’re interested in trialling a copy or getting pricing info drop us a line.

August 8, 2014

Detect Which Web Page IE Is On – Keep It Simple

Filed under: Automation,Scripting — Marcus Tettmar @ 9:43 am

Today we had two different support requests asking how to have a Macro Scheduler macro determine which page IE is on.

One person was asking about using Image Recognition for that. You could also use the IE functions to examine the HTML or look for the existence of a specific HTML element.

You could do one of those, sure, but I think that’s over complicating things.

My motto is “keep things simple”.

IE’s Window Title adopts the page title of the web page it is displaying. IE also shows the URL in the address bar. So why not just look at one of those. Like this:

//Two simple methods to see which page IE is at.

//Method One - Just look at the window title
IfWindowOpen>Bing - Internet Explorer
  //Bing is open - do this
Else
  IfWindowOpen>Google - Internet Explorer
     //Google is open - do that 
  Endif
Endif

//Method Two - Look at the Actual URL in the URL bar - I used the Wizard to get this code and then altered the window title to make it a substring match
UIGetValue>- Internet Explorer*,{"Address"},curVals,Positions,nHeight
Position>google.co.uk,curVals,1,pGoogle
If>pGoogle>0
  //must be at google
Else
  //must be somewhere else
  Position>bing.com,curVals,1,pBing
  If>pBing>0
    //must be at bing
  Endif
Endif
« Newer PostsOlder Posts »