Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to have my cygwin sh program open when I hit Windows Key + R (this could just as easily apply to any other key combination), but I realize that all of my computers may not have cygwin installed. In the case where my computer doesn't have cygwin, I'd like to just open the Windows Command Prompt.

How do I conditionally set the #r (Win+R) mapping to attain this?

share|improve this question
Windows Key + R is already mapped to bring up the run prompt. It might be easier to go for an unclaimed key combination than re-writing system behavior. – SpecKK Oct 11 '10 at 21:12
@SpecKK: Nope; it's pretty easy for me to overwrite that behavior. I've mapped Win+R to cmd for quite a while now. – palswim Oct 11 '10 at 22:18

This is untested, but should get you started:

Run sh
if ErrorLevel
   ;it timed out waiting for sh (1 sec)
   Run cmd

It attempts to run the sh cygwin command. Using the WinWait function, it checks to see if it was created (using a window title of "sh", that may need to be changed). If not, it falls back to run cmd.

Another option, if you always know the absolute path of sh.exe, you can use the FileExist method.

if FileExist("c:\cygwin\sh.exe")
   Run sh
   Run cmd
share|improve this answer
up vote 1 down vote accepted

@yhw42's answer did get me started, but I've found a cleaner solution:

WinR := "sh"
RunWait, where sh
if ErrorLevel
    WinR := "cmd"

#r::Run %WinR%

This uses the Windows WHERE command and AutoHotkey variables.

share|improve this answer
Unfortunately, this only works on Windows Server 2003 or later (i.e. not Windows XP). – palswim Oct 12 '10 at 17:46
That is better! (i.e. check once when the script is loaded) – yhw42 Oct 21 '10 at 23:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .