How to convert .webloc files to .url, and vice versa? (Big Sur)

I used to use a neat little utility called Web Location Converter, which converts both ways, but it doesn't work in Big Sur (presumably it's 32-bit, dating from 2009). Anybody know of a contemporary utility of this type?

MacBook Pro 15″

Posted on Jan 14, 2024 5:33 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 14, 2024 10:46 AM

Here is a two-way Zsh script that can convert .webloc or .url files into the opposite format.


Double-clicking either file result will open that URL in the default browser.


Code:


#!/bin/zsh

: <<"COMMENT"
Convert .webloc or .url files to the opposing format.

Usage: urlwebloc.zsh [ name.webloc | name.url ]
Tested: macOS Sonoma 14.2.1, Zsh 5.9
COMMENT

NETFILE="${1:a:s/\~\//}"

function make_webloc () {
    osascript <<-AS
    use framework "Foundation"
    use AppleScript version "2.4"
    use scripting additions

    property NSMutableDictionary : a reference to current application's NSMutableDictionary
    property NSString : a reference to current application's NSString

    set outFile to "${2}"
    -- next two lines create the .webloc .plist
    set dict to NSMutableDictionary's dictionaryWithCapacity:1
    dict's setObject:${1} forKey:"URL"
    dict's writeToFile:outFile atomically:true
    return
AS
}

# match extension
case "${NETFILE:e}" in
    webloc)
        # convert .webloc to .url which are text files
        URL=$(/usr/bin/plutil -extract URL raw -o - -- "${NETFILE}")
        # just the .webloc filename without extension
        COMMENT="${NETFILE:r:t}"
        # same path and basename as the webloc file
        OUTNAME="${NETFILE:r}.url"
        URLFMT="[InternetShortcut]"
        URLFMT+="\nURL=${URL}"
        URLFMT+="\nCOMMENT=${COMMENT}"
        print "${URLFMT}" > "${OUTNAME}"
        ;;
    url)
        # convert .url to .webloc which are .plist files
        # force double-quotes around URL variable to make proper .webloc entry
        URL=\""$(/usr/bin/sed -En 's/URL=(.*)$/\1/p;' "${NETFILE}" | tr -d '\r\n')"\"
        make_webloc ${URL} "${NETFILE:r}.webloc"
        ;;
    *)
        echo "Bogus input file… exiting"
        ;;
esac
exit 0



2 replies
Question marked as Top-ranking reply

Jan 14, 2024 10:46 AM in response to HandyMac

Here is a two-way Zsh script that can convert .webloc or .url files into the opposite format.


Double-clicking either file result will open that URL in the default browser.


Code:


#!/bin/zsh

: <<"COMMENT"
Convert .webloc or .url files to the opposing format.

Usage: urlwebloc.zsh [ name.webloc | name.url ]
Tested: macOS Sonoma 14.2.1, Zsh 5.9
COMMENT

NETFILE="${1:a:s/\~\//}"

function make_webloc () {
    osascript <<-AS
    use framework "Foundation"
    use AppleScript version "2.4"
    use scripting additions

    property NSMutableDictionary : a reference to current application's NSMutableDictionary
    property NSString : a reference to current application's NSString

    set outFile to "${2}"
    -- next two lines create the .webloc .plist
    set dict to NSMutableDictionary's dictionaryWithCapacity:1
    dict's setObject:${1} forKey:"URL"
    dict's writeToFile:outFile atomically:true
    return
AS
}

# match extension
case "${NETFILE:e}" in
    webloc)
        # convert .webloc to .url which are text files
        URL=$(/usr/bin/plutil -extract URL raw -o - -- "${NETFILE}")
        # just the .webloc filename without extension
        COMMENT="${NETFILE:r:t}"
        # same path and basename as the webloc file
        OUTNAME="${NETFILE:r}.url"
        URLFMT="[InternetShortcut]"
        URLFMT+="\nURL=${URL}"
        URLFMT+="\nCOMMENT=${COMMENT}"
        print "${URLFMT}" > "${OUTNAME}"
        ;;
    url)
        # convert .url to .webloc which are .plist files
        # force double-quotes around URL variable to make proper .webloc entry
        URL=\""$(/usr/bin/sed -En 's/URL=(.*)$/\1/p;' "${NETFILE}" | tr -d '\r\n')"\"
        make_webloc ${URL} "${NETFILE:r}.webloc"
        ;;
    *)
        echo "Bogus input file… exiting"
        ;;
esac
exit 0



Jan 14, 2024 10:54 AM in response to HandyMac

Hello,


Roger Wilmut1

User level: Level 10 131,121 points

Nov 24, 2020 5:50 AM in response to scott1212

It's easier simply to open the URL you want and create another webloc. However, if you really feel impelled to do this, drag the webloc icon onto the TextEdit icon. The change the URL in the 'string' tag and save the file.


This will work, but it won't change the filename of the webloc: you can change that in the usual way by clicking twice ()not fast) on the filename.


You may need to do a Get Info on it & give yourself Permisions to R&W. :)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to convert .webloc files to .url, and vice versa? (Big Sur)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.