1

I use multiple browsers, and I created a bash script that checks to see which browser is open and opens web pages in whatever browser is already open. I use Windows 7, so I run this script using Cygwin. I set the script as the default browser by editing the appropriate registry entries, so whenever any program tries to open a web page, it calls this script using Cygwin's "--login" parameter. The script works - pages get loaded in whatever browser is open. However, whenever the script is called by another program, I get the error message, "There was a problem sending the command to the program." The script works, but I get the error message anyway. This only happens when the script is called by another program - there's no error message if I run the script directly from the command line.

I don't know if the script is at fault, but here it is:

#! /bin/bash

if ps -W | grep -v grep | grep waterfox.exe >/dev/null
    then
        "/cygdrive/c/Program Files/Waterfox/waterfox.exe" -requestPending -osint -url "$1"
    elif ps -W | grep -v grep | grep firefox.exe >/dev/null
    then
        "/cygdrive/c/Program Files (x86)/Mozilla Firefox/firefox.exe" -requestPending -osint -url "$1"
    elif ps -W | grep -v grep | grep chrome.exe >/dev/null
    then
        "/cygdrive/c/Users/Morgan/AppData/Local/Google/Chrome/Application/chrome.exe" -- "$1"
    else
        cygstart "/cygdrive/c/Program Files/Waterfox/waterfox.exe" -requestPending -osint -url "$1"
fi
exit

I tried changing the last line to "exit 0" on the theory that there was some problem with the exit status, but that had no effect.

I'd really appreciate it if someone wiser in the ways of Cygwin and/or Windows could enlighten me. Thanks!

1 Answer 1

1

I don't know what's happening with your original script, but considering you are running Windows 7, you can try using Windows PowerShell instead:

Param([string] $Url)


function Count-Process ([string] $Name) {
    return (Get-Process -Name $Name -ErrorAction SilentlyContinue).Count
}

function Invoke-Browser ([string] $Url) {
    if ((Count-Process waterfox) -gt 0) {
        & "C:\Program Files\Waterfox\waterfox.exe" -requestPending -osint -url $Url
    } elseif ((Count-Process firefox) -gt 0) {
        & "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -requestPending -osint -url $Url
    } elseif ((Count-Process chrome) -gt 0) {
        & "${Env:LocalAppData}\Google\Chrome\Application\chrome.exe" -- $Url
    } else {
        & "C:\Program Files\Waterfox\waterfox.exe" -requestPending -osint -url $Url
    }
}


if ($MyInvocation.InvocationName -ne '.') {
    Invoke-Browser $Url
}

Save this in a file with extension .ps1 and call it with PowerShell -WindowStyle Hidden -ExecutionPolicy Bypass -File Path\To\Script.ps1 %1.

7
  • I can't get this to work, unfortunately. It ran without a hitch when I ran it manually from the command line, but after adding it to the appropriate registry entries it didn't work. I got different errors when it was called by different programs this time, but they were all some variation on "application not found". (And unlike with the bash script, the script actually failed to open the web pages.) Thanks for trying, though!
    – Morgan May
    Jan 10, 2013 at 15:46
  • 1
    @MorganMay Try specifying the full path to PowerShell: C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe Jan 10, 2013 at 23:03
  • Changing the registry entries to use the full path fixed the "application not found" error. However, now the PowerShell script behaves exactly the way the bash script did: it successfully opens web pages, but generates the same error as before: "There was a problem sending the command to the program." So I guess that rules out bash/Cygwin as the source of the problem, at least.
    – Morgan May
    Jan 11, 2013 at 5:47
  • Yes, that's not the problem then. Does this happens with all the browsers? Jan 11, 2013 at 5:59
  • Yes, it does. I get the same error messages regardless of which browser is in use.
    – Morgan May
    Jan 11, 2013 at 6:20

You must log in to answer this question.

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