July 23, 2008

Creating a windows shortcut using AutoIt

Filed under: autoIt,robo coding Himanshu @ 6:07 am

AutoIt library do have function to create windows shortcut, FileCreateShortcut. AutoIt script to create new shortcut of specified target in specified file/folder. Once compiled and created executable, use it in following way.

Usage:

shortCut.exe  []

First parameter is required and should be path of file/folder for which to create shortcut

Second parameter is optional and if specified, should be full existing path including shortcut file name. If not specified shortcut will be created in the folder from where executable is run.

If ($CmdLine[0] < 1) Then
    MsgBox(16, "Error", "Insufficent parameters. In first parameter, specify for which file, shortcut should be created.") 
    Return 
EndIf 
$shortcutOf = $CmdLine[1] 
If (Not FileExists($shortcutOf)) Then 
    MsgBox(16, "Error", "File/directory """ & $shortcutOf & """ do not exists") 
    Return 
EndIf 
$shortcutPath = @WorkingDir & "\" & "Shortcut of " & 
$shortcutOf & ".lnk" 
If ($CmdLine[0] = 2) Then 
    $shortcutPath = $CmdLine[2] 
    If (StringLower( StringRight($shortcutPath , 4)) <> ".lnk" ) Then 
        $shortcutPath = $shortcutPath & ".lnk" 
    EndIf 
EndIf 
$objShell = ObjCreate("Wscript.Shell") 
$shortcut = $objShell.CreateShortcut($shortcutPath) 
$shortcut.TargetPath = $shortcutOf 
$shortcut.WindowStyle = 1 
$shortcut.Save()

If you want to download script file click here

Let me know if you need any further help in it.

March 11, 2008

Create shortcuts by scripting (AutoIt, AutoHotKey)

Filed under: autoIt,robo coding Himanshu @ 12:01 pm

In windows, one can create shortcuts; Windows shortcuts can point to may resources like URL, an executable file, document files or folder in file system, disk, and network shares. But not all are same in their behavior. For example: If I create shortcut of an executable and put that shortcut in one of the directory which is included in PATH (Environment variable), I can invoke executable by just typing in shortcut name in Start->Run (Windows + R Key). But I could not do same with http URL. I also wanted to parameterize some of them. For example if I type in “jira ata-586”, it should open jira item “ata-586”.

I use AutoIt for quite some time. There are many good things about AutoIt, easy to learn it’s language (almost like VB), can create executable from script, comes with SciTE Script Editor along with plug-in for language and libraries of AutoIt. Because of plug-in SciTE can give nice code complete feature. I have also been using AutoHotKey a bit. One of the nice features of AutoHotKey is you can program it to wait until specific keys are pressed to perform certain operations, recording keyboard keystrokes and mouse gestures. And also supports to create executable from script.

It’s good to create this kind of scripts that will minimize effort to locate specific place that once can access on regular basis. I have created windows shortcuts or script shortcuts for following specific tasks that I perform regularly

  • Open folder of my projects in windows explorer. (“cd ata” or “cd pub”)
  • JIRA home page
  • JIRA space of specific project
  • Specific JIRA issues
  • Confluence Dashboard
  • Specific confluence space.
  • http://dictionary.reference.com with specific word
  • Google with specific search result.
  • Cisco vpn connection
  • Mapping network share to a drive letter
  • Starting tools that I regularly use, like specific version of visual studio, reflector, vmplayer, nunit…
  • Logging in to application that I’m working/testing
  • Fill-in form that I’m working
  • ….

Big list, I also recommend all to do same for the tasks that you regularly perform, and make you life easier.

Powered by WordPress