August 7, 2007

Keep it Simple – Shortcuts and Applications

Filed under: Automation,Scripting — Marcus Tettmar @ 7:47 am

We had a customer email us the other day having a problem getting his macro to work reliably. He wanted to start an application, so he had written a macro to left click on the application’s shortcut on the desktop. But sometimes the icon moved. He wanted to know how to reliably know where the icon was.

Reality check. There’s an easier way! You don’t need to know where the icon is.

Let’s just think about this for a second. What is a shortcut? As its name suggests it’s a shortcut to something. In this case the shortcut was to an application. We need to start the application. So why not start it directly? Why click on the shortcut at all?

Right clicking on the shortcut and selecting properties tells us the path of the application in the “Target” field. Usually all we need to do is copy that and stick it in a Run Program command:

Run Program>C:\Program Files\FileZilla\FileZilla.exe

Occasionally an application needs to start in a different folder. In the shortcut properties you’ll see a field called “Start in”. If necessary copy the value there and put it in a Change Directory command. So we end up with:

Change Directory>C:\Program Files\FileZilla
Run Program>C:\Program Files\FileZilla\FileZilla.exe

You can even run a shortcut itself:

ExecuteFile>C:\Documents And Settings\Marcus\Desktop\FileZilla.lnk

This way the shortcut is executed just as if you clicked it and all the attributes of the shortcut are used.

No mouse clicks needed!

If you really *do* want to find an icon on the desktop reliably, use Image Recognition.

Or you can even use keystrokes to invoke a shortcut.

SetFocus>Program Manager
Send>FileZilla
Press Enter

But for just starting an application, all this is rather unnecessary. Run the application directly.