4 Replies Latest reply: Jan 20, 2008 4:47 PM by dev_sleidy
gnizm Level 1 Level 1 (0 points)
The title pretty much explains it. Say, if I had a folder of Webloc files, I'd like to convert the whole folder to HTML URL's (something I could upload and view as a list). If Apple script could do this, that would be so amazing.

macbook pro, Mac OS X (10.4.8)
  • None Level 2 Level 2 (245 points)
    This is pretty primitive, but works here on 10.4.3. Maybe you can improve on it. Save as an application and drop one or more weblocs or filelocs on it. It should make a simple HTML page on the desktop.

    Peter B.

    --

    on open these_items

    set linked_URLs to ""

    tell application "Finder"
    set these_items to sort these_items by name
    end tell

    repeat with this_item in these_items

    tell application "Finder"
    set this_item to this_item as text
    set item_name to the displayed name of file this_item
    end tell

    set webloc_text to read file this_item to eof

    set ASTID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to "<string>"
    set webloc_URL to text item 2 of webloc_text
    set AppleScript's text item delimiters to "</string>"
    set webloc_URL to text item 1 of webloc_URL
    set AppleScript's text item delimiters to ASTID

    set linked_URL to "<A HREF=" & "\"" & webloc_URL & "\"" & ">" & item_name & "" & return & "
    "

    set linked_URLs to linked_URLs & linked_URL

    end repeat

    set page_header to "<HTML>"
    set page_footer to "</HTML>"

    set output_file to (path to desktop as text) & "webloc_links.html"

    try
    open for access file output_file with write permission
    write page_header & return & linked_URLs & return & page_footer to file output_file starting at 0
    close access file output_file
    on error
    close access file output_file
    end try

    end open

    -----
  • None Level 2 Level 2 (245 points)
    The Discussions server appears to have stripped out some of the HTML tagging in the 'set linked_URL to...' line. The script should generate a list, not a continuous line.

    See if you can figure out what the missing tags were.

    Peter B.

    -----
  • gnizm Level 1 Level 1 (0 points)
    I am at best an amateur at Applescripting, I am learning. I got errors when I ran the script. Thanks for the effort though.

    If I discovering anything interesting, I will report back. If anyone else can contribute, that would be excellent.

    This would be a great way to select specific folders in Safari's bookmarks, drag them to desktop, convert those Webloc files to URLs, and upload them to Del.icio.us
  • dev_sleidy Level 4 Level 4 (1,570 points)
    View the 'Applescript to convert Webloc to HTML?' entry at 'dev-sleidy-AppleScript', for an alternative solution.