Last time I showed you how to create a simple VBScript macro that closed Cardbox and reopened it again, so as to restart any interrupted Internet connections.
The macro had to be executed from Windows – for instance, from the Quick Launch area of the taskbar. What about creating a Cardbox macro that can do the same thing from inside Cardbox?
You might think that because Cardbox uses VBScript as its macro language, just taking the VBScript macro and copying it into Cardbox would work – but it wouldn’t. This is because the macro closes Cardbox by making it invisible and then letting go of it so that there is no reason for it to stay open. But when Cardbox is running a macro it has to stay open to keep the macro going, so this trick won’t close it. Here is the solution.
Create a file called “Reopen2.vbs” and put the following code into it:
WScript.Sleep 1000 WScript.CreateObject("WScript.Shell").Run """" & WScript.Arguments(0) & """"
Save it somewhere on your hard disk.
In Cardbox, create a macro called something sensible like “Restart Cardbox”, and put the following code into it:
Const Reopen2="C:\Documents and Settings\Owner\Desktop\Reopen2.vbs" Application.Visible=False Launch Reopen2,"""" & Application.Workspace & """"
Obviously, change the filename in the first line to reflect the place where you actually saved your “Reopen2.vbs” macro.
Like any Cardbox macro, you can arrange for “Restart Cardbox” to be activated by a keystroke or a toolbar button or a menu item.
How it all works
“Restart Cardbox” makes Cardbox invisible. Then it tells Windows to start running “Reopen2”.
When “Restart Cardbox” finishes, there is no reason for Cardbox to stay open: the user can’t see it, and it isn’t running a macro any more. So Cardbox closes.
“Reopen2” sits and does nothing for a whole second (1000 milliseconds). This is to allow time for Cardbox to close.
Finally, “Reopen2” opens the Cardbox workspace again.