Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
share|improve this answer
add comment
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.