6

I recently tried to open a URL link I saved onto my desktop by double clicking it, but it will not open correctly. If I DRAG & DROP the file into chrome works fine.

The code of the file is as follows:

[InternetShortcut]
URL=https://www.textnow.com/login

the file is saved with a ".url" extension

If I double click on the file I'm prompted by finder to choose which application to open it with (Chrome is greyed out, but I choose 'All Applications' and then choose Chrome), it will then simply load a page in Chrome and display the code on the page, instead of opening the url specified in the code.

running Version 50.0.2661.94 (64-bit) on OSX 10.9.5

1
  • 1
    I made a .url file using your example and get the same results as you. – user3439894 May 6 '16 at 21:11
5

This is a known issue with Google Chrome. See:Chrome doesn't recognise .url files properly

The workaround it to use an Extension such as .URL Handler

Once installed you need to go to Chrome > Preferences... > Extensions (chrome://extensions/) and check the [✔] Allow access to file URLs check box.

enter image description here

3
  • IS there a similar feature for Ubuntu ? These Chrome extenstions do not work on Ubuntu – Kalamalka Kid May 6 '16 at 21:35
  • 1
    @Kalamalka Kid, I haven't looked to see about Ubuntu as this forum is for Apple stuff. Stack Exchange has an Ask Ubuntu forum too. – user3439894 May 6 '16 at 21:38
  • 1
    As of March 23, 2020, Chrome version 80.0.3987.149, this .URL extension doesn't work anymore. No solution. – Zvi Twersky Mar 23 '20 at 11:47
1

OK did some digging around. It turns out that Google Chrome's security model normally doesn't allow clicking on .url files to open them.

There is a Chrome extension that will allow this though so the solution is easy for OSX users.

0

As URL files are just text files, I have solved this problem by attaching a script as handler to them, which reads the URL from the file and opens that URL with the default web browser. The following Nim script does this. I only tested it on my own operating system, but it should also work on Linux and macOS.

You need to compile it. Install Nim and then run nim compile urlhandler.nim on it. Then assign your URL files to the created executable.

# urlhandler.nim

import os, system, re, browsers, strutils, strformat

# You can change this. Use lowercase.
let URLEXTS = [".url", ".open"]

# ↑ I added the '.open' file type because on my OS it is not trivial to attach
# new programs to the URL filetype in the default file explorer. So lets create a
# new filetype, and attach this exe to it. Then batch renaming *.url files to
# *.open files (programmatically or by hand) shouldnt be too difficult, is it?

var url: string
block:
    proc bye(reason: string) =
        echo "*** ERROR ***"
        echo "\n" & reason
        echo "\n(press key to close)"
        discard readLine(stdin)
        quit()

    var oldname: string
    block:
        try:
            oldname = commandLineParams()[0]
        except IndexDefect:
            bye "Please provide a file"
        oldname.normalizePath
        if not oldname.fileExists:
            bye fmt"{oldname} does not exist"
        oldname = oldname.expandFilename

    let (_, title, ext) = oldname.splitFile
    let cleanext = ext.toLower

    if cleanext in URLEXTS:
        let filecontents = readFile(oldname)
        if filecontents.isEmptyOrWhitespace:
            bye fmt"{title & ext} is empty."
        let urlpattern = re(
            """
            ^ \s* URL \s* = \s* ( [^\s]+ )
            """,
            flags = {reExtended, reMultiLine}
        )
        var matchgroups: array[1, string]
        if filecontents.find(urlpattern, matchgroups) > 0:
            url = matchgroups[0]
        else:
            bye fmt"""
            {title & ext} has an unknown format. I was expecting something like ...

                [InternetShortcut]
                URL=https://nim-lang.org/

            ... but instead i got ...

            """.dedent &
            filecontents.strip.indent(4)
    else:
        bye fmt"""unsupported filetype: "{ext}". If you want to have it """ &
        "supported, add it to the URLEXTS list."

openDefaultbrowser(url)

-1

Alternatively, you can use the terminal for this. The terminal can then open the URL on the corresponding web browser.

open -a "Google Chrome" https://www.textnow.com/login 
1
  • This doesn't address the problem described in the question, which might explain the downvote you got. But using the Terminal is a good idea actually, something like open -a "Google Chrome" $(sed -n '/^URL=/s/^URL=//p' shortcut.url) would actually work. – nohillside Apr 2 at 8:41
-3

Although this is problem for BROWSER (not Apple) I will add solution for Windows too:

Open Start>Settings>System>Default apps and check that Google Chrome is chosen under Web Browser. Also open up Choose default apps by file type, scroll down to .url file and choose "Internet Browser" next to it.

You must log in to answer this question.

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