Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 12 Nov 2018, 18:04
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
How to make MS .URL files open in your default browser
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [21 Posts]   Goto page: 1, 2 Next
Author Message
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Sun 29 Oct 2006, 21:12    Post subject:  How to make MS .URL files open in your default browser  

Open Microsoft .url files in your default browser (or a different one if you want). If you use Opera you don't need this.
-----------------------
EDIT 9-04-07
Version 3 attached. You can see the new code further down this page. Basically it might open some .url files that might not have worked before, and can open multiple files at once from the command line (e.g. openurl *.url). If you will use this functionality read the comments in the code, as you can have dillo open them in tabs or windows, you may want to change when it will work if you use Firefox, and you'll have to edit it to make it work with Seamonkey. Also read the first edit below.
-----------------------
EDIT 27-03-07:
Package now attached to this post - in Puppy 1.x, and I believe up to 2.12, install with Pupget as an alien package, and either restart ROX/Puppy or right click in a ROX window->options->types->re-read files. See below for Puppy 2.13 and above.

PACKAGE CONTENTS:
-an updated (you can see it further down this page) /usr/bin/openurl script that I believe will now open all .url files (unless MS do them differently in Windows Vista). If you want to open .url files in something other than your default browser, replace "defaultbrowser" in this script with whatever command you want to use eg "Dillo" or "Firefox"...
-/root/Choices/MIME-info/microsofturl and /root/Choices/MIME-types/text_url that make Rox use the script to open .url files when you click on them.
-/usr/local/share/Choices/MIME-icons/text_url.xpm to give .url files an icon.

PUPPY 2.13 AND ABOVE (Rox 2.x)
I do not understand how mimetypes work with Rox 2.x, so I only made a package that works with Rox 1.2, found in Puppy up to 2.12
In Puppy 2.13 upwards, or if you have installed a newer version of ROX than came in Puppy, you can install the package, but will have to manually set the run action and icon for .url files using the right-click menu in a ROX window. For the run action just add openurl at the start of the command and click the button to use the command. I believe when you set an icon there is an option to use it for all of that type of file.


PROBLEMS, IMPROVEMENTS ETC
Please tell me if you find any problems with it, or even better, post a fix yourself Smile
Post the contents of any .url files that it will not open.

If you like, you are encouraged to:
- make a new icon - I just discovered that this one looks awful if you don't have medium sized icons/thumbnails in ROX, and also is a bit overpowering in a folder full of .url files.
- package it properly as a Dotpup or whatever.
- port it properly so that it works in Puppy 2.13 upwards automatically.
- tell me how to rewrite it so that when you open a file you can either use the default browser, or choose another one.

---------Done but if you can make it work all the time with Firefox and Mozilla please do-----------
tell me how to rewrite it so that you can run it from the command line with multiple input files eg:
Code:
openurl *.url
as at the moment it will just open the first one, and if you want to open several you have to use Opera, which does not need openurl (try
Code:
opera *.url
). I am sure this is easy, I just don't know how.




Original post follows
----------------------------


This is what you do if you want to be able to click on Microsoft .URL files to open them in your default browser:




1. Make a text file called "microsofturl" (or actually called whatever you like) in /root/Choices/MIME-info/ (you might have to make the folder too).
Put in it this:

# Mime type for Microsoft .url

text/url
ext: url URL


2. Make a text file called "text_url" in /root/Choices/MIME-types/
Put in it this:

url=`tail +2 "$1" | head -n 1`
url=`echo ${url#URL=}`
exec defaultbrowser $url

3. Restart X or your computer or go into the ROX options (from the right-click menu in a ROX window)->Types->Re-read files




It should now work.
IMHO this should be built into Puppy Very Happy
Ideally we should put the second file somewhere where it can be run from the command line (and call it something like "openurl"), and put a link to it in the MIME-types folder - in Puppy 1.x it will disappear from /bin on reboot, and I am not sure the most appropriate place for it - help anyone?
I might make a dotput (or someone else can), but just want to see if anyone thinks I should change anything first.
openurl3.tar.gz
Description  Latest Version
gz

 Download 
Filename  openurl3.tar.gz 
Filesize  5.59 KB 
Downloaded  530 Time(s) 
openurl1.tar.gz
Description 
gz

 Download 
Filename  openurl1.tar.gz 
Filesize  4.59 KB 
Downloaded  509 Time(s) 

Last edited by disciple on Sun 08 Apr 2007, 20:33; edited 6 times in total
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Fri 23 Mar 2007, 01:30    Post subject:  

Oh no!!! I just discovered there are some files this script will not work on... any files in the Windows favourites.
I'll see if I can adapt it to work for them.
Back to top
View user's profile Send private message 
John Doe

Joined: 01 Aug 2005
Posts: 1689
Location: Michigan, US

PostPosted: Fri 23 Mar 2007, 02:19    Post subject: Re: How to make MS .URL files open in your default browser  

Do you by any chance move the Favorites Shell Folder via the Windows registry and/or store it in an encrypted location? That would cause problems from linux in the accessing favorites there. Also if one is on an Active Directory Terminal without physical or admin access linux isn't practical to retrieve one's favorites.

Do you know how to get the link name with logic like this?

disciple wrote:
url=`tail +2 "$1" | head -n 1`
url=`echo ${url#URL=}`


I would love to create a Linux based Windows favorite import utility also (assuming one could access the favorites directory of said machine one was running on).
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Fri 23 Mar 2007, 06:15    Post subject:  

Quote:
Do you by any chance move the Favorites Shell Folder via the Windows registry and/or store it in an encrypted location?


No. It doesn work because the files there have additional lines that .url files do not normally have, before and/or after the standard lines, and I had never found out because I never tried to open one there before, as I don't use the Windows favourites, as I use Firefox on Windows.

Quote:
Do you know how to get the link name with logic like this?


I'm sorry, I don't quite understand the question - please clarify.
Are you talking about getting the name of a favourite for your import utility to use? If so all you need to do is delete the last four characters from the name of the .url file.

I am afraid I wrote this so long ago that I have now forgotten everything I learned about Bash in doing so, so it will take me a while to get this sorted out [and I am busy Smile!]

I think to work on all url files a script must find the location of:

[InternetShortcut]
URL=

and delete everything up to and including it, and then find the first line break and delete everything after it.

(playing around in a terminal)
Aaah. I see. The first line of my script takes the content of the file, deletes the first line of content with tail, deletes all lines except the second (well - now it is the first) with head, and assigns it to the variable "url".
The second line takes "url", removes the first four characters, and reassigns the output to "url".
The third line starts the default browser using the content of the variable "url" as an argument.

So... I've found a tutorial on shell scripting that seems to be what I need, but for some reason a lot of the examples do not work - if they did I could put together a script that worked with no problems at all. This sounds familiar - last time it resulted in me finding a much more elegant solution than I would have come up with at first.

Time to go to bed.
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Tue 27 Mar 2007, 00:49    Post subject:  

I have updated the script so that it (I believe) works with all .url files. I have also made a package, with icon etc - see the first post.
I want help on improving it - see first post.

This is the updated code:

linebefore=`fgrep -in [InternetShortcut] "$1" | awk -F":" '{print $1}'`
line=`expr $linebefore + 1`
url=`tail +$line "$1" | head -n 1`
url=`echo ${url#URL=}`
exec defaultbrowser $url
Back to top
View user's profile Send private message 
John Doe

Joined: 01 Aug 2005
Posts: 1689
Location: Michigan, US

PostPosted: Tue 27 Mar 2007, 02:12    Post subject:  

Sounds great.

I'll check it out and try to loop out a puppy based MS FAV import util.
Back to top
View user's profile Send private message 
John Doe

Joined: 01 Aug 2005
Posts: 1689
Location: Michigan, US

PostPosted: Thu 05 Apr 2007, 01:17    Post subject:  

Thanks for the help, check it out:

Import IE Favorites to Mozilla BookMark File Format (BASH)

http://www.murga-linux.com/puppy/viewtopic.php?p=108317

p.s. note the sed I dropped in on the last line. I found that some of my dad's favorites seemed to have a newline char at the end and some don't. They might have been imported from 98/95 or so.
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Thu 05 Apr 2007, 19:00    Post subject:  

Good work - that should be really useful.
Re the sed - I am confused - I thought
Code:
head -n 1
took care of newline chars - does it only deal with carriage return chars?. Should that be added to the code for what I am doing, or is it just needed when used inside your script?

You seem to be rather more competent than me. Perhaps you could help make my script work with multiple inputs. I had expected this to work:
Code:
for i in "$@"
do linebefore=`fgrep -in [InternetShortcut] "$i" | awk -F":" '{print $1}'`
line=`expr $linebefore + 1`
url=`tail +$line "$i" | head -n 1`
url=`echo ${url#URL=}`
exec dillo $url
done

but I get the error
Code:
expr: non-numeric argument

If I add an
Code:
echo $linebefore
it has the correct output, so I can't fathom what is going wrong.
Back to top
View user's profile Send private message 
John Doe

Joined: 01 Aug 2005
Posts: 1689
Location: Michigan, US

PostPosted: Fri 06 Apr 2007, 01:24    Post subject:  

disciple wrote:
Good work - that should be really useful.


Thanks! I'm hoping people find it useful. I was thinking of making a tiny gui, desktop entry and pet package for it. I just have no idea how to do a nice gui yet. I tinkered some with GTK, maybe that will be the route. If anyone would like to throw out a couple lines of script to select a directory and pass it to a script, that would help.

disciple wrote:
Re the sed - I am confused - I thought 'head -n 1' took care of newline chars - does it only deal with carriage return chars?. Should that be added to the code for what I am doing, or is it just needed when used inside your script?


I dropped that in because during my testing I was having trouble getting the bookmark file to actually import to mozilla. Turns out that didn't fix the problem in itself, but perhaps was a factor. I didn't go back and remove it and test again.

One observation along that way was that some of the url's I was importing (fortunately I had a REALLY messy test environment) were printing line breaks of some kind *when viewed in geany*. In retrospect it may have been a cr vs. nl issue, perhaps head -n doesn't cover both. Although best practices would dicatate that I leave it in because regardless if it caused the problem or not the offending bits sould be removed if present.

I tried to cover a couple whitespace characters in there (didn't know if sed just had a special character for that).

It's possible that those bookmarks were imported from 98. Some in there even had truncated file names, missing the extension and some of the name. I believe they were possibly copied off a cd.

disciple wrote:
You seem to be rather more competent than me.


Much appreciated, but don't let the final code fool you. There was a large amount of swearing, screaming and me pounding the kitchen counter while cursing bash script during all of that. Smile

disciple wrote:
Perhaps you could help make my script work with multiple inputs. I had expected this to work:
Code:
for i in "$@"
do linebefore=`fgrep -in [InternetShortcut] "$i" | awk -F":" '{print $1}'`
line=`expr $linebefore + 1`
url=`tail +$line "$i" | head -n 1`
url=`echo ${url#URL=}`
exec dillo $url
done

but I get the error
Code:
expr: non-numeric argument

If I add an
Code:
echo $linebefore
it has the correct output, so I can't fathom what is going wrong.


The only thing I can think of is putting a newline or terminator ';' (without 's) after the 'do'. Perhaps it's trying to read the string expression as a numeric input value and throwing that error?
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Sat 07 Apr 2007, 05:10    Post subject:  

Ah - I think a lot of my problems are because I've been using leafpad, and there is encoding information or something in the file that I can't see. Copying another script and putting this in:
Code:

#!/bin/bash

for i in "$@"
do linebefore=`fgrep -in [InternetShortcut] "$i" | awk -F":" '{print $1}'`
line=`expr $linebefore + 1`
url=`tail +$line "$i" | head -n 1`
url=`echo ${url#URL=}`
exec defaultbrowser $url
done

it now works again - but it still only opens the first .url file Sad (using a file created by leafpad gives me an error about an invalid interpreter if I put that first line in.)
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Sat 07 Apr 2007, 17:31    Post subject:  

If I comment out
Code:
exec defaultbrowser $url
and put in
Code:
echo $url
then it works as expected - so I just need to tell it to do that line and keep going - the script is pausing after opening the browser the first time, and then exiting when the browser is closed.
Back to top
View user's profile Send private message 
GuestToo
Puppy Master

Joined: 04 May 2005
Posts: 4078

PostPosted: Sat 07 Apr 2007, 19:13    Post subject:  

exec executes a command ... and never comes back ... nothing after an exec command is executed

if you want it to open the url with defaultbrowser, wait until the browser is closed, then open the next url in the defaultbrowser and wait for it to close, etc etc, you can so this:

defaultbrowser $url

if you want it to open the urls in defaultbrowser windows all at once, without waiting between urls, you can so this:

defaultbrowser $url &
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Sun 08 Apr 2007, 06:32    Post subject:  

Thanks! That's great. I can't believe I never asked myself what the exec was actually for.
New code, version 2:
Code:
#!/bin/sh
# Script to open Microsoft .url internet shortcut files.  Opera can do this itself.
# Made by Disciple.  Version 2, April  8, 2007.
# http://www.murga-linux.com/puppy/viewtopic.php?p=108935#108935
# If you can improve this (e.g. by adding an optional argument to choose the browser when running the script from the command line) please do so :)


# For each input file.
for i in "$@"

# Find the right place in the .url file.
do linebefore=`fgrep -in [InternetShortcut] "$i" | awk -F":" '{print $1}'`
line=`expr $linebefore + 1`

# Extract the url.
url=`tail +$line "$i" | head -n 1`
url=`echo ${url#URL=} | sed 's/[ \t\n\r]*$//'` # John Doe added the sed in his IE Favourites Import script (http://www.murga-linux.com/puppy/viewtopic.php?p=108317) - I'm not certain that it is needed for this.

# Start browser.  If you use Dillo, and maybe some other browsers (not Firefox or Mozilla), for multiple files you can make it open one url at a time by removing (or commenting out) the & (Thanks GuestToo!).  This will not work with Firefox or Mozilla, but will with Dillo and maybe other browsers.  If you don't want to use the default browser you can of course replace it with "mozilla", "firefox" or "dillo" (no quotes) etc.
defaultbrowser $url &

done


It actually works best with Dillo. With Firefox and Mozilla, if you don't have the browser already open, it will only open the first file, as it will try to open the others before the browser has opened, and these browsers won't let you open them again while they are already opening. I cannot think of a way to work around this.

Sorry - I am being sent to bed and I haven't finished cleaning up this post - I posted before realising the problem.
Back to top
View user's profile Send private message 
disciple

Joined: 20 May 2006
Posts: 6863
Location: Auckland, New Zealand

PostPosted: Sun 08 Apr 2007, 20:18    Post subject:  

Version 3. Read the comments - it's just more evidence that Opera is the best browser, and Dillo the second best Smile
I think the Firefox problem is the fault of the mozilla people, and the seamonkey problem is because we have it set up in a strange way in Puppy.
Code:

#!/bin/sh
# Script to open Microsoft .url internet shortcut files.  Opera can do this itself.
# Made by Disciple.  Version 3, April 9, 2007.
# http://www.murga-linux.com/puppy/viewtopic.php?p=108935#108935
# If you can improve this (e.g. by adding an optional argument to choose the browser when running the script from the command line, or to specify whether to open the pages in tabs or browser windows, or (most usefully) by making it work properly with Firefox and Seamonkey) please do so.   :)


# For each input file.
for i in "$@"

# Find the right place in the .url file.
do linebefore=`fgrep -in [InternetShortcut] "$i" | awk -F":" '{print $1}'`
line=`expr $linebefore + 1`

# Extract the url.
url=`tail +$line "$i" | head -n 1`
url=`echo ${url#URL=} | sed 's/[ \t\n\r]*$//'` # John Doe added the sed in his IE Favourites Import script (http://www.murga-linux.com/puppy/viewtopic.php?p=108317) - I'm not certain that it is needed for this.

# Append url to the browser argument.
addresses="$addresses $url"

done

# Start browser.
# You can of course replace defaultbrowser with a custom browser command e.g. if you want to add arguments you can, or if your defaultbrowser is Seamonkey and you want to use Dillo, you can just put "dillo" without the quotes.
# At the moment opening multiple .urls will not work with Seamonkey (as set up in Puppy) or with Firefox if the browser is already open, as these browsers do not handle arguments consistently.
# If you want it to work when Firefox is already open you can add "-new-window" before "$addresses", but it then won't work when the browser is not open.
# You can open all the files in Seamonkey if you comment out this last line, and replace the whole addresses line above with "seamonkey $url &".  It will only work though if Seamonkey is already open.  I guess for this and the previous Firefox suggestion you could make the script open the browser at the start and then wait a sufficient length of time for the browser to open before doing anything else, and it would work whether or not the browser was already open.
# It works great with Dillo and Opera (but Opera can do it all by itself).
# You can open all the files in separate Dillo windows by commenting out this last line, and replacing the addresses line above with "dillo $url &".
defaultbrowser $addresses &


BTW I give up. The issues with Firefox/Seamonkey are too much for me.
Back to top
View user's profile Send private message 
arizonagroove

Joined: 17 Aug 2007
Posts: 2

PostPosted: Fri 17 Aug 2007, 11:19    Post subject:  

Having read this thread I'm left thinking that the method of extracting the url from the .url file is overly complicated and that one could just use


Code:
url=`grep ^URL "$i" | sed 's/URL=//'`


Am I showing my ignorance by missing the reason why that won't work?
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [21 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1391s ][ Queries: 12 (0.0180s) ][ GZIP on ]