A new article has been added to the knowledge base: Loop the Loop – all about the different ways you can create loops in Macro Scheduler.
April 11, 2014
March 27, 2014
Why doesn’t SHIFT-ESC stop my compiled macros?
You might find that when you run a compiled macro and you also have Macro Scheduler running, Shift-Esc – the default stop key sequence – doesn’t stop the compiled macro.
This is because the stop key sequence is a system wide hot key. And system wide hot keys can only be registered for use by one application at a time. So if Macro Scheduler is already running when you start your .exe the .exe is unable to register Shift-Esc because Macro Scheduler already has it.
Of course when you deploy your .exe to people who don’t already have Macro Scheduler – which is usually the case – there won’t be any problem because Macro Scheduler won’t be running and so your .exe is able to register the Shift-Esc hot key.
But what if you want to define your own stop hot key, or you want to give your users the option of setting it? Well what you need is a KEY_DOWN event handler:
//CTRL-Z is stop key OnEvent>KEY_DOWN,VK90,2,doExit Let>paused=FALSE //sample code here ... Wait>20 MessageModal>hello SRT>doExit Exit>0 END>doExit
Here we have set up a key down event handler for CTRL+Z. VK90 is Z and 2 is the modifier key for CTRL. See the OnEvent help topic and Virtual Key Codes List.
The event handler basically sets up a concurrent thread that is running all the while the main script is running. This allows it to respond to events such as this KEY_DOWN event. So when you hit the specified key sequence – in this case CTRL+Z, the doExit subroutine runs and all that does is call the Exit function which terminates the script.
You could be smarter and ask the user if he really means he wants to exit:
SRT>doExit Ask>Are you sure you want to exit?,ynExit If>ynExit=YES Exit>0 Endif END>doExit
When you compile the macro there is an option to disable the standard Shift-Esc sequence. So you could do that to completely replace the stop key system with your own custom one using your OnEvent.
Consider an INI file and possibly another config script using a custom dialog to allow the user to set his own stop key sequence. Other apps could already be using it. My CTRL+Z example is probably not ideal as although it is used in Linux to suspend the current process it is usually the short cut for Undo in Windows.
March 18, 2014
Recursion – Get A List of All Subfolders
Someone was asking how to get a list of subfolders. You can do that with the GetFileList command by setting GFL_TYPE to 1. That gives you the folders in the specified path. But it turns out he wanted a recursive list – i.e. one that drills down through all levels.
To do that you need a recursive function. In Macro Scheduler we can do this by making a subroutine call itself. I’ve added an example on the Scripts ‘n Tips forum. Here.
http://www.mjtnet.com/usergroup/subfolder-recursion-t8185.html
For a bit of fun go to Google and search for “recursion” and see what you get:
February 20, 2014
Problems Sending Keystrokes to Citrix?
If you’re seeing odd results when trying to send keys to Citrix Receiver windows try going into legacy mode:
Let>SK_LEGACY=1
Send>some text
February 11, 2014
Reading from System Event Logs
Just been asked how to read from the system event log (what you see in Windows Event Viewer) using Macro Scheduler.
As it happens there’s already an example of monitoring the event log for specific event types and responding to them in the Scripts n Tips forum here.
So I’ve taken that code and modified it slightly to return a list of all entries for a given event code. Here is the script:
Although I’ve added code to allow you to retrieve ALL events I would not advise it as that could take A. VERY. LONG. TIME.
I’ve added this example into the Scripts n Tips forum. Here.
December 27, 2013
Christmas Morning 1972 – Macro Scheduler Arcade – From JRL
Hope you all had a wonderful Christmas. I expect many of you are still enjoying some holiday time. Well if you are here’s some Macro Scheduler fun from forum regular JRL.
Yes, it’s a two player 1970s computer game written entirely with Macro Scheduler code. Here’s the code
See JRL’s forum post and grab the code here: http://www.mjtnet.com/usergroup/christmas-morning-1972-t8106.html
Paste it into a new Macro Scheduler macro, hit run and off you go. Up and down arrows control the right hand paddle, A/Z the left. Enter to start, Esc to end. Happy Memories! Enjoy 🙂
If you don’t have Macro Scheduler you can download a trial version here.
December 10, 2013
Print Excel File Automatically
Thanks to Alberto Voli for this little tip. The code below can be used to print an Excel file without having to manipulate the printer dialogs. It uses VBScript to interface with Excels’ COM object model to call it’s PrintOut method.
Place the VBSTART .. VBEND lines near the top of your script ready for use. To use modify the path to the Excel file in the VBRun line and place that line where needed.
You can use this approach with other Microsoft Office Apps, e.g. Word. A good tip is to record a macro within Excel or Word using it’s own macro recorder. This will create VBA code. You can then view the VBA code to figure out what objects and methods you need. You can then convert it to VBScript which you can run inside Macro Scheduler.
October 24, 2013
Making your macros intelligent with If, Else, and Endif
The power and flexibility of Macro Scheduler makes this an easy task.
There are hundreds of different reasons you might want to do this. Maybe it’s dependent on :
- The answer to a question.
- The success/failure of an operation.
- The contents of a file.
- If a file or folder exists.
- If a certain mathematical goal is reached (e.g. if>count=100).
- If a certain image is visible on the screen.
- If the value of a cell in an Excel spreadsheet matches your requirement.
- If an email was/wasn’t successfully sent.
- If a value on a web page matches your criteria.
- The day/date/time or year
That’s just a handful of the many hundreds of variables we can check, but the basic rules of IF, Else, and Endif are always the same.
Let’s use asking a simple yes/no question as an example. We simply tell the macro something like this:
Ask a yes/no question
If the answer is yes
Then do thisIf the answer is no
Then do that
It’s that simple! So, how do we put that into simple Macro Scheduler language? Here’s how :
//ask a yes/no question Ask>Do you like brussel sprouts?,question //depending on the answer given, the macro will execute *one* of the two lines below, then continue on with the rest of the script If>%question%=YES MessageModal>I agree, but let's keep it our secret Else MessageModal>Right. They're ghastly Endif //you can abbreviate messagemodal to mdl mdl>OK, on with the rest of this script.
Ask>Do you like brussel sprouts?,question If>%question%=YES MessageModal>I agree, but let's keep it our secret Else MessageModal>Right. They're ghastly Endif mdl>OK, on with the rest of this script.
If>your condition is/isn't met //do this //or else Else //do that Endif
If>your condition is met //This line only executes if the condition is met, otherwise it's ignored Endif
Questions? Reply to this thread. Our support team and our community are always happy to help.
October 3, 2013
Automating Google
This has come up a few times lately so I thought I’d post it here.
One or two people have been asking about writing a Macro Scheduler script that performs a Google search and pulls back the resulting URLs. They have discovered that trying to automate Google can be awkward because of the dynamic nature of the page. As soon as you type in the search box the page changes because it is updating in real time.
Some people suggested using HTTPRequest to get the page content directly and then parse it with RegEx. This can be done but is also tricky because you’re getting back all the dynamic code and other stuff like adwords ads etc and it is hard to find the right patterns.
There’s an easier way. Use their API URL instead. E.g.:
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Apple%20Pie&rsz=large&start=1
This performs a search for “Apple Pie”. Try it in your browser and you’ll see the content is less cluttered and it is easy to parse. It returns 8 results. For the next 8 you would change the start parameter to 9, and so on.
So here’s a simple example script which takes a search term, specifies how many results to get, extracts the URLs and writes them to a text file:
September 3, 2013
From the Archives: Making EXEs Respond to Hotkeys
How do you make compiled macros respond to hotkeys?
Here’s how: http://www.mjtnet.com/blog/2007/11/20/exes-and-hotkeys/