Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Determining HTML document relative links in AS



Hi all,

I got asked something from a user of my application, and would appreciate any insight for trying to achieve this. Although this looks much more like a HTML query at first sight... it is ultimately AppleScript related!

A bit of background info:

The application creates a HTML log file listing (clickable) images that it has created. The log file is *always* created on the User's Desktop and the image files are stored in a used defined folder (in this example, I use a folder called "tFolder" placed on the Desktop as well. For a given image, the href and src tags are defined by:

tell application "Finder" to set encoded_target_file to URL of rsz_target_file
--> "file://localhost/Users/DizzyP/Desktop/tFolder/Art%20Pepper%20- %20Meets%20The%20Rhythm%20Section"

set log_ to "<a href=\"" & encoded_target_file & "\"><img src=\"" & encoded_target_file & "\" width=75 height=75 border=0></a>"

It then would look like this in the source of the HTML log file:

<a href="file://localhost/Users/DizzyP/Desktop/tFolder/Art%20Pepper%20- %20Meets%20The%20Rhythm%20Section">
<img src="file://localhost/Users/DizzyP/Desktop/tFolder/Art%20Pepper%20- %20Meets%20The%20Rhythm%20Section" width=75 height=75 border=0></a>

Now all this works perfectly, but would there be a way to reference the image with a "Document relative link", meaning relative to the HTML log file as opposed to "localhost"? (Why? you ask... well, this would enable the user to upload the log and images without having to change all the links, and also work fine on the user's computer).

Assuming that the "tFolder" is on the Desktop, making the links "Document relative" is straightforward and easy:

<a href="tFolder/Art%20Pepper%20-%20Meets%20The%20Rhythm%20Section">
<img src="tFolder/Art%20Pepper%20-%20Meets%20The%20Rhythm%20Section" width=75 height=75 border=0></a>

But what happens if the "tFolder" is created somewhere else, let's say in /Users/DizzyP/stuff/tFolder?

I suppose just comparing the path strings of both the HTML log file and the "tFolder", and removing the bits that match and adding "..//" will do the trick:

<a href="file:../tFolder/Art%20Pepper%20- %20Meets%20The%20Rhythm%20Section">
<img src="file:../tFolder/Art%20Pepper%20-%20Meets%20The%20Rhythm%20Section" width=75 height=75 border=0></a>

But how to deal with it if the User decides to create the tFolder lower down the folder hierarchy, or on a different partition or volume?

My big question is... is there a proven AppleScript way of easy-ing the process of determining a valid "Document relative link" without jumping through hoops? (FYI, the HTML log file is *always* created on the User's Desktop).

Your help much appreciated!

DP
--
DizzyPenguin * autoMAC-it
mailto:email@hidden
visit: http://www.dizzypenguin.com/automac-it/
_______________________________________________
applescript-studio mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-studio
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.