0

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?

2
  • 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, 2010 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, 2010 at 22:18

2 Answers 2

3

This is untested, but should get you started:

#r::
Run sh
WinWait,sh,,1
if ErrorLevel
{
   ;it timed out waiting for sh (1 sec)
   Run cmd
}
return

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.

#r::
if FileExist("c:\cygwin\sh.exe")
   Run sh
else
   Run cmd
return
1

@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.

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

You must log in to answer this question.

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