Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > How to get URL info out of .webloc files in the shell ???

How to get URL info out of .webloc files in the shell ???
Thread Tools
Posting Junkie
Join Date: Nov 2000
Location: in front of my Mac
Status: Offline
Reply With Quote
Feb 4, 2005, 08:55 AM
 
I have quite a collection of links on my disk as .webloc files. From time to time I ssh into my Mac from a Linux box. Since .webloc files store the URL in a resource fork I can't do
% more bookmark.webloc
or a
% strings bookmark.webloc
because the data fork is empty. Is there any way to extract the URL in the command line?
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Feb 4, 2005, 09:18 AM
 
cat someurl.webloc/rsrc dumps the binary, which includes the URL in plaintext. In general the resource fork is accessible by appending /rsrc.

It'll take a little fiddling in Perl to cleanly extract the URL itself, but it shouldn't be too hard.
     
Simon  (op)
Posting Junkie
Join Date: Nov 2000
Location: in front of my Mac
Status: Offline
Reply With Quote
Feb 4, 2005, 09:34 AM
 
Originally posted by Mithras:
cat someurl.webloc/rsrc dumps the binary, which includes the URL in plaintext. In general the resource fork is accessible by appending /rsrc.

It'll take a little fiddling in Perl to cleanly extract the URL itself, but it shouldn't be too hard.
Mithras, many thanks! I didn't know the trick with appending /rsrc to get the resource fork of the file

% strings bookmark.webloc/rsrc
prints the URL on the fourth line in clear text.

Great. Thanks!
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Feb 4, 2005, 09:41 AM
 
Sure. In the meantime I made this, although 'strings' will probably do you fine.
Code:
perl -ne '@ASCII = unpack("C*",$_); $in_url = 1; for($i=312; ($i < scalar @ASCII and $in_url == 1); $i++) {if ($ASCII[$i] == 0) { $in_url = 0; } else { print chr($ASCII[$i]); } }; print "\n";' < someurl.webloc/rsrc
Or, as a script that you can call with scriptname.pl someurl.webloc/rsrc:
Code:
#!/usr/bin/env perl while (<>) { @ASCII = unpack("C*",$_); $i = 312; # starting position while ($i < scalar @ASCII and $ASCII[$i] != 0) { print chr($ASCII[$i]); $i++; } print "\n"; }
(Last edited by Mithras; Feb 4, 2005 at 09:52 AM. )
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:08 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2