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

Fix an error in a sample Safari AppleScript Web Browsers
The Applescript "Display Thumb-linked images" from Apple's Safari scripting page doesn't work (even on their own example page!). Here's how to get it to work.

Open the script up with script editor. Find the following lnelines:
set the images_list to {}
repeat with i from 1 to number of items in image_links
  set this_item to item i of image_links
  if this_item does not contain "http:" then
    set the target_URL to my parse_imagepath(this_item)
    if the target_URL ends with ".jpg" then
      set the end of the images_list to the target_URL
    end if
  end if
end repeat
Change them to the following. I've put in comments to show what I did, and will explain why below.
set the images_list to {}
repeat with i from 1 to number of items in image_links
  set this_item to item i of image_links
  --if this_item does not contain "http:" then
  set the target_URL to my parse_imagepath(this_item)
  -- the next line was just ".jpg"
  if the target_URL ends with ".jpg" or target_URL ends with ".JPG" then
    set the end of the images_list to the target_URL
  end if
  --end if
end repeat
Read the rest of the hint for the explanations and one more subtle change...

Firstly, on the example site, all the images' links are not relative and therefore do contain the text "http:". This causes the list of image urls to be empty - hence the error message. The other change causes files ending in ".JPG" to be found too. exercise to the reader - I'm sure there are many other file type extensions that could be added here too.

OK, but one more problem to solve. The script expects the images to have relative URLs - and will therefore prefix the "parent url" onto the image urls - this is not what you want if they contain "http://blah/" - you get "http://blah/http://image". So when we loop round opening each window, we need to be a little careful. The line:
  set the image_URL to (the parent_URL & this_item) as string
needs to read
  if this_item does not contain "http:" then
    set the image_URL to (the parent_URL & this_item) as string
  else
    set the image_URL to this_item as string
  end if
So we only append a parent or base URL when the image path is relative. Done!

Another possible modification would be to check that non-relative URLs contain the "parent" URL or at least the same domain name, thus stopping thumb-links to counters and the like. Have fun!

[robg adds: These changes worked for me when I tested the revised script on the example page...]

    •    
  • Currently 1.50 / 5
  You rated: 3 / 5 (4 votes cast)
 
[9,099 views]  

Fix an error in a sample Safari AppleScript | 1 comments | Create New Account
Click here to return to the 'Fix an error in a sample Safari AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Download page together with images
Authored by: shucks on Feb 26, '03 09:53:35PM

I'm trying to get a similar script working. What i need is for the applescript to 1. scrape through a page for links. 2. Follow the links. 3. Download the resulting page together with its images into my disk. Any ideas?

---
He Travels Far Who Travels Alone, If He Knows The Way That Is



[ Reply to This | # ]