Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'The faster way of conversion of multiple Safari .webloc to .url files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
The faster way of conversion of multiple Safari .webloc to .url files
Authored by: juanfc on Mar 12, '08 02:03:25AM
This is the Perl way, and then faster one. Easy to change and to read and very fast.

#!/usr/bin/env perl
# juanfc 2008-03-04
# 
use warnings;
use strict;

for my $arg (@ARGV) {
    open my $source, "strings '$arg/rsrc' |" or die "'$arg' not open: $!";

    my $s="[InternetShortcut]\r\nURL=";
    my ($urlname, $fname);
    my $ln = 0;
    my $already_got = 0;
    while (<$source>) {
        ++$ln;
        chomp;
        if (m|^.http://|) {
            if (!$already_got) {
                $s .= substr($_, 1) . "\r\n";
                $already_got = 1;
            }
        } elsif ($already_got) {
            $urlname = $_;
            last;
        }
    }

    close $source;

    if ($urlname and $urlname ne "drag") {
        $fname = $urlname . ".url";
    } else {
        $fname = $arg . ".url";
    }

    open my $dest, ">$fname" or die "Not able to create '$fname': $1";
    print $dest $s;
    close $dest;
}

---
---
juan

[ Reply to This | # ]