Marcus' Macro Blog

Mostly tips, tutorials, articles and news about Macro Scheduler & Windows Automation

Archive for the ‘Web/Tech’ Category



Tweetlib: A DLL Plugin for Tweeting Status Updates via oAuth

Tuesday, May 25th, 2010

As noted yesterday I have been waiting on Twitter to provide xAuth access. They declined, saying it was not appropriate. I’m not really sure why.

No matter, I decided to make a small DLL to simplify Tweeting from Macro Scheduler. It uses the full oAuth interface.

Implementing oAuth in Macro Scheduler code would require lots of VBScript code and would be very complicated (although doable in theory). So instead I decided to create a DLL which you can use in Macro Scheduler to tweet in one line of code.

You can download it here.

And then to post a status update all you need to do is something like this:

Let>message=Hello from Macro Scheduler
LibFunc>%SCRIPT_DIR%\tweetlib.dll,UpdateStatus,r,message,buff,1024

Note that the first time you call UpdateStatus you will be asked to log into Twitter and click “Allow” to authorise Macro Scheduler to access your account. You will then be given a PIN to enter. You only need to do this once. If you ever need to revoke access and start over call the RemoveCredentials function. Your Twitter username and password are NOT stored anywhere. This uses the oAuth authorisation scheme which provides an access token. It is the access token which is stored and this only allows Macro Scheduler to access the API for your account.

The return buffer will contain the XML of the status update operation if successful or an error message if not.

See readme.txt and sample .scp in the zip file. Enjoy.

[Post to Twitter] Tweet This

Tweeting from Macro Scheduler Without the API

Monday, May 24th, 2010

A while back I posted an article showing how to Tweet via Twitter’s API. It uses basic authentication which Twitter plan to turn off in the near future. The alternative, oAuth is awkward for desktop based apps, but xAuth is now available and should be doable in Macro Scheduler. I have requested xAuth access from Twitter and, assuming it’s doable, will try and provide an example once I’ve received it and tried it out.

In the mean time it occurred to me that we don’t really need an API if all we want to do is send a status update. We can do that easily using Macro Scheduler and WebRecorder functions by controlling an instance of Internet Explorer, which can be done in the background.

Below is a script which demonstrates this. It offers a function called LoginToTwitter which need only be called once per session, and an UpdateStatus function to update your status. Just set your Twitter username and password in the first two lines and you should be all set.

Let>TW_USERNAME=XXXXX
Let>TW_PASSWORD=XXXXX

//only need do this once per session
GoSub>LoginToTwitter

GoSub>UpdateStatus,This is a test

GoSub>UpdateStatus,This is a test 2

GoSub>LogOut

// END

//*** SUBROUTINES ***//
SRT>LoadWR
  //load the WebRecorder runtime
  LibLoad>IEAuto.dll,hIE
  If>hIE=0
    MessageModal>Could not load IEAuto.dll, make sure it is in the path or edit the LibLoad line.
    Exit>0
  EndIf
END>LoadWR

SRT>LoginToTwitter
  GoSub>LoadWR
  //open IE
  LibFunc>hIE,CreateIE,ieTwitter,0
  LibFunc>hIE,ShowIE,res,ieTwitter,1

  //log in to Twitter
  LibFunc>hIE,Navigate,r,ieTwitter,http://twitter.com/login
  LibFunc>hIE,WaitIE,r,ieTwitter
  LibFunc>hIE,FormFill,r,ieTwitter,,,session[username_or_email],TW_USERNAME,0
  LibFunc>hIE,FormFill,r,ieTwitter,,,session[password],TW_PASSWORD,submit

  LibFunc>hIE,WaitIE,r,ieTwitter
  Wait>1
  LibFunc>hIE,WaitIE,r,ieTwitter
  Wait>1
END>LoginToTwitter

SRT>UpdateStatus
  LibFunc>hIE,FormFill,r,ieTwitter,,,status,UpdateStatus_VAR_1,submit
  LibFunc>hIE,WaitIE,r,ieTwitter
  Wait>1
END>UpdateStatus

SRT>LogOut
  LibFunc>hIE,KillIE,r,ieTwitter
END>LogOut

You need the IEAuto.DLL library which is installed with WebRecorder.

For a bit of fun the following code copies the currently highlighted text to the clipboard and tweets it. So assigned to a hot key it can be used to tweet any text from any application.

Press CTRL
Send>c
Release CTRL
WaitClipBoard
GetClipBoard>theText
GoSub>UpdateStatus,theText

The real challenge is finding something useful to do with it! :-)

[Post to Twitter] Tweet This

Choose Your Web Browser

Thursday, March 4th, 2010

One of my Windows XP systems installed an automatic update last night when I shut it down.  This morning I was presented with this:

Windows EU WebBrowser Choice

As I understand it this is as a result of an EU competition law decision.   Is this a good thing or a bad thing?

On the one hand it seems a waste of money and illogical.

I’m no fan of IE, but why shouldn’t Microsoft build a web browser and make it part of their operating system?  Should the EU force them to offer a choice of text editors, calculators, paint programs and calendar applications too? Where should it end?

Plus, yet another dialog like this is surely going to confuse the ordinary user.  Many have no idea what a “web browser” is and just call it “My Internet” or “Google”.  The dialog preceding the one above has to go to the trouble of explaining what a web browser is.  And isn’t the user just going to take the first option anyway?  In which case should the EU force Microsoft to make IE8 something other than the default option?

But then if I were trying to sell a web browser I guess I would welcome this decision. It might give me a little extra exposure.

What do you think?

[Post to Twitter] Tweet This

Running Macro Scheduler Macros over the Web Via PHP

Friday, January 29th, 2010

Here’s a quick and simple proof of concept for running Macro Scheduler macros via the web and having their output displayed in the user’s browser:

Running Macro Scheduler Macros Over the Web Via PHP

The screenshot shows the PHP script, Macro Scheduler script and Internet Explorer being used to run the macro.

1) If you don’t already have a Windows based web server with PHP running, download and install WAMPServer. It’s easy.

2) Create a simple PHP script which takes an EXE name as a parameter and any parameters you want to pass to it. The following script will run EXEs that are in the c:\wamp\ folder, passing in any parameters provided and will dispay the EXEs output.

<?php
$exe = $_GET['exe'];

$dir = "c:\\wamp\\";

$parms = "";
foreach($_GET as $key=>$val) {
  $parms .= "/$key=$val ";
}

echo shell_exec("\"$dir$exe\" $parms");
?>

3) PHP’s safemode must be disabled for this script to work.

4) Create a Macro Scheduler macro and use SOWrite or SOWriteLn to output information. Compile it with the “Create Console App” option checked. Compile the EXE (or copy it) to the c:\wamp\ folder.

5) Now the macro can be executed via the web using http://servername/runmacro.php?exe=my.exe&parm1=value&etc=… which could be a link or entered into the browser directly.

6) Consider adding further security to the script to prevent anyone running any EXE on your server, or putting it in a password protected folder. I’ll leave that to you.

Macro Scheduler Enterprise comes with the msNet Remote Controller which includes a CGI module for running Macro Scheduler macros via web servers.

[Post to Twitter] Tweet This

Twittering from Macro Scheduler with the Twitter API

Monday, April 20th, 2009

Way back in the deep and distant past when the Internet was new and Bill Gates thought it was just a passing fad, I remember reading about a Cola vending machine on a University campus that some frivolous young boffins hooked up to the ‘net so that you could check its inventory from anywhere in the world using an old fashioned network command called “finger”. Why? Because they could.

Fast forward to the technologies of the current day and the latest trend of Twitter, and history is repeating itself. In the last week I’ve read about a restaurant that can take orders via Twitter, a bakery tweeting the emergence of fresh loaves from the oven; and, utterly pointless, some guys who created a system which sends a tweet every time their cat enters or exits its cat flap. Why? Well, because they can I guess.

Not wanting to be left out I decided to write some Macro Scheduler code to tweet status updates and monitor replies. Why? Well there might be a good reason for being able to do this – I’m sure someone will have one. Perhaps you have a client who wants you to set up a system to monitor the movement of his cat, process restaurant orders, or your local baker wants an automated fresh-loaf tweeter! But mostly, it’s because we can.

You’ll find the Twitter API documentation here. Here’s the code to Tweet a status update:

Let>username=YOURTWITTERNAME
Let>password=YOURPASSWORD

//Tweet from Macro Scheduler
Let>url=http://%username%:%password%@twitter.com/statuses/update.xml
Let>message=Kitty just left the buildng
HTTPRequest>url,,POST,status=%message%,result

Being serious for a moment I can see how a macro that monitors an application might want to post status updates to Twitter, or a backup script could alert you by Twitter when there’s a problem. It might be a public system, but don’t forget that Twitter profiles can be made private too, and Tweets can be viewed on and sent from your BlackBerry, iPhone, or even by SMS.

The following script sets up a loop which monitors your Twitter stream for “mentions” of your username. This might form the basis of a script which retrieves orders. Perhaps it could listen to Twitter for commands and carry out actions based on what message was sent. Or perhaps you just want a macro which does something when a cat decides to head out for the night. Use your imagination.

Let>username=YOURTWITTERNAME
Let>password=YOURPASSWORD
Let>ini_file=%SCRIPT_DIR%\twit.ini
Let>_delay=30

VBSTART
VBEND

//monitor twitter username "mentions" loop
Label>monitor_loop

Let>url=http://%username%:%password%@twitter.com/statuses/mentions.xml
HTTPRequest>url,,GET,,result

//remove the  portion (I don't need it and it avoids distinguishing the text IDs from the user IDs.
RegEx>[^>](.*?),result,0,user_matches,nf,1,,result

//extract all texts
RegEx>(?<=)[^>]*?(?=),result,0,text_matches,num_texts,0
If>num_texts>0
  //extract all ids
  RegEx>(?<=)[^>]*?(?=),result,0,id_matches,num_ids,0

  //get last known
  Let>last_known_id=0
  IfFileExists>ini_file
    ReadIniFile>ini_file,SETTINGS,LAST_ID,last_known_id
  Else
    WriteLn>ini_file,wlnr,
  Endif

  //iterate through texts
  Let>k=0
  Repeat>k
    Let>k=k+1
    Let>this_id=id_matches_%k%
    If>this_id>last_known_id
      Let>msg_text=text_matches_%k%
      /*
      msg_text contains the message
      Use your imagination here!
      For now we'll show it in a message
      */
      MessageModal>msg_text
    Endif
  Until>k=num_texts

  //store last ID
  EditIniFile>ini_file,SETTINGS,LAST_ID,id_matches_1
Endif

Wait>_delay
Goto>monitor_loop

The script retrieves the 20 most recent “mentions”. It stores the last seen ID in an INI file so that on the next check it ignores those it has seen before, only retrieving messages with a larger ID number.

This is a quick and dirty solution with no error checking, using RegEx to parse the XML that is returned by the call to Twitter. You may prefer to use the MS XML object as shown here.

Whether this proves useful or completely pointless, I hope you have fun. If you’re using Macro Scheduler with Twitter, please add a comment below to let us know how … and why!

Don’t forget you can follow me on Twitter where I may occassionally say something useful.

[Post to Twitter] Tweet This

It’s time to bring down IE6!

Monday, March 23rd, 2009

Bring Down IE6

Some of you may remember that we had some issues with Internet Explorer 6 support when we released our new web site. I made some negative comments about IE6. And I was being polite. Unfortunately IE6 is still in use in millions of companies and, as I mentioned in that last post, some 35% of our web traffic is delivered by people using IE6. If it were up to me I’d banish it to web browser hell.

So I’m all for a new campaign from .Net magazine: Bring Down IE6.

If you have the power to do so, upgrade now, or try out Firefox or Google Chrome . If you’re working for a company that locks down their PCs and forces you to use IE6, get vocal – educate your colleagues and IT department. Petition them to lift you out of the dark ages! :-)

Check out the site to see how you can get involved.

[Post to Twitter] Tweet This

Twitter – What, Why, How?

Thursday, February 5th, 2009

If you’re one of those who has heard of Twitter but just doesn’t quite “get it” yet you should find Scott Hanselman’s How To Twitter – First Steps and a Twitter Glossary useful. It explains what Twitter is, why it’s useful and how to tweet.

I didn’t get it at first. I wasn’t quite sure what I would get out of it. Most people who now use Twitter regularly were probably the same to begin with. Now I realise how useful it is. I follow friends, people and companies that I find interesting and I want to stay up to date with. I follow news sites like the BBC and CNN. I probably get most of my news via Twitter now (In our house the TV seems to be permanently tuned to Nick Jr these days!). Most of the bloggers I read now tweet their blog updates, so I no longer need to monitor their RSS feeds.

It’s useful. It’s fun too. Even if you don’t have anything to say, you can get a lot out of following people that interest you. And, as Scott says, the nice thing is if you want to respond you can just jump in and reply to anyone.

So if you’ve been wondering what all the fuss is about, read Scott’s blog post, jump in and join the conversation. You can start by following me. My twitter ID is http://twitter.com/marcustettmar :-)

[Post to Twitter] Tweet This

Firefox2 or IE7?

Thursday, October 19th, 2006

I see IE7 has been released. Haven’t installed it yet, but I do have an early beta version running on another PC and found that a bit clunky. I’m a Firefox fan though, so I’ve just downloaded and installed Firefox 2 RC3. I like it. The interface has been given a subtle update but it is also noticeably faster. I really like the built in spell check. I used to use the Google toolbar to spell check my posts, when I remembered – I invariably forgot! So having spell check built in is a great improvement. Now I just need to change the dictionary from US English to British English! :-)

You can download Firefox 2 RC3 here.

[Post to Twitter] Tweet This

A Few Search Tips

Friday, August 25th, 2006

In my last post I said I would provide some tips on getting the best out of Google Groups and finding what you’re looking for. But first off let’s start with a few general search tips. Google themselves provide some helpful guides on using the regular Google search engine:

Basic Tips:
http://www.google.com/help/basics.html

Advanced Search:
http://www.google.com/help/refinesearch.html

These guides are well worth reading. There’s lots of stuff on the Advanced Search page that are easy to overlook and can be very helpful in narrowing down your search. For example, you can limit your search to a particular domain. I often use this for searching for answers on Microsoft’s site. E.g.:

“not allowed in this context” site:microsoft.com

Note that the advanced search simply adds information to the regular search query. To search within a domain it simply adds the “site:” attribute to the search term. You can add this yourself in the regular search box. You can also exclude results from certain sites:

“Macro Scheduler” -site:mjtnet.com

Note the use of the quote marks to search for a specific phrase. In my first example above I wanted to find pages on microsoft.com that contained this error message. So I needed to use the quotes.

Google Groups searches Usenet messages. It works in much the same way as Google. But since Usenet consists of a huge array of groups spanning all manner of topics it is often necessary to narrow your search down to within certain groups. Consider this Google Groups search:

create recordset

The first page of results consists of messages from various groups covering VB, SQLServer, MS Access, Dreamweaver and Ultradev. What I really want to do is find out how to create a record set in VBScript. In much the same way the regular Google search lets you search within specific domains, you can search within specific groups:

create recordset group:microsoft.public.scripting.vbscript

This searches only within the microsoft.public.scripting.vbscript newsgroup. But there are other groups that discuss VBScript. And what if you don’t know what they are called? Well, you can use wildcards:

create recordset group:*vbscript*

This returns a much more targeted, useful set of results from various VBScript groups. Definitely my most used search construct.

Hope this helps!

[Post to Twitter] Tweet This

Usenet – My Best Kept Secret

Thursday, August 24th, 2006

In a way I feel I’m about to blow my own cover with this post. But I’m pretty sure many people will find this really useful. I seem to have a reputation for knowing everything. People always come to me with their computer problems and I’m nearly always able to find a solution. When I help Macro Scheduler customers with obscure VBScript, ODBC, or Win32 API, issues they often ask “How the hell do you know this stuff?”.

The truth is I very often don’t have the answers immediately. Sometimes a support ticket will come in or I’ll see a forum post and I’ll be no more able to answer it than anyone else. But I have my secret weapons. And the fact is anyone else can use them too.

My favourite and most useful resource is Usenet. I take Usenet for granted, but I’ve realised lately that many people these days don’t know what Usenet is. Usenet is an email like distributed discussion system that was invented at Duke University (North Carolina, USA) by two graduate students in 1979. Yes, you heard that right, the best resource for answering technical questions for state-of-the-art problems is 27 years old! With Usenet, users read, post and reply to messages to a huge number of ‘newsgroups’ on all manner of topics. Newsgroups are distributed across ‘news servers’ throughout the Internet. Most ISPs have a news server that their subscribers can access.

Usenet is home to all sorts of weird and wonderful topics. Discussions of all sorts take place in Usenet. There are literally thousands and thousands of groups. Many I’d rather have nothing at all to do with! But Usenet is also the domain of programmers, technical whizkids and geeks of all varieties. And since it has been around for so long there’s almost no technical issue, programming problem or computer scenario that hasn’t been discussed at some point. So it is the perfect place to go to find out how to build that bit of VBScript, use a Win32 API function, or fix a problem in XP.

But Usenet is a bit tricky to use. You need to be able to access a news server and then you need a news reader, which is like an email client. You need to subscribe to relevant groups and then you get overwhelmed as thousands of posts pour in. And then somehow you need a way to search the content.

So Usenet is great for day to day discussions, but how do you tap this resource as a knowledge base? Well you may have heard of a company called Google. A while back Google bought a system called Deja News which archived every Usenet post since 1981. The system is now called Google Groups. It continues to archive Usenet postings as well as Google’s own web based discussion groups. It can be accessed at groups.google.com. As you probably know, Google is quite good for searching for stuff. Google Groups is no different. It combines the power of Google’s search with the massive resource of Usenet. With Google Groups you can search for pretty much any technical matter you need help with. And 99% of the time you’ll find an answer, often from a technical guru who knows his stuff, or someone who has had the same problem already.

I find that people tend to turn to Google, or one of the other search engines, to try to find answers. But specific technical questions can be hard to locate on Google, because Google indexes web sites, and even if the issue is dealt with by a web site it may be hidden deep within it’s bowels. So a web search engine isn’t always the best way to find answers to technical problems. In contrast Google Groups indexes only messages that people, like geeks and programmers, have written, and so it gets straight to the crux of the matter. It’s also instant. Pretty much as soon as a Usenet message is posted, it shows up in Google Groups. In contrast a web site can take months before it is fully indexed. So Usenet is often more up to date on technical matters.

As an example you will probably find more discussion of Vista technical issues and Vista specific programming techniques in Usenet than anywhere on the web. Long before Vista is released, beta testers, Microsoft experts and C++ gurus have been discussing such concepts via Usenet for months. And you can find this stuff now with Google Groups.

So now you know! I’m not such an expert after all. I just know where to find the answers. In my next post, I’ll explain how to get the most out of Google Groups and give you some tips on how to search and narrow down on what you’re looking for.

[Post to Twitter] Tweet This