On Dec 10, 2016, at 02:58, jgill <[email protected] 
<mailto:[email protected]>> wrote:
> This script, which I don't understand as I don't know Python or shell 
> scripts, gives '../../Commoner Species Photos/Shag.htm', which has an extra 
> ../ at the beginning. 


Hey Joe,

I'm just a dabbler with Python (at present), so I can't answer that.

> I could chop of the first three characters but I don't understand why they 
> are there in the first place.

Python and Ruby have many tools for doing web-related tasks, so there may be 
ways to fine-tune the output.

Keep it in mind when you're looking for solutions.

On the AppleScript front:

-------------------------------------------------------------------------------------------

set pathToRelativize to "/Users/jgill/Documents/Web/CHOG/CHOG1and1/Archive 
Photos/Juvenile-Shag.jpg"
set referencePath to "/Users/jgill/Documents/Web/CHOG/CHOG1and1/Commoner 
Species Photos/Shag.htm"

set relativePath to getRelativePath(referencePath, pathToRelativize)

--> "../Archive Photos/Juvenile-Shag.jpg"

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on getRelativePath(refPath, filePath)
   set relativePath to {}
   set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text 
item delimiters, "/"}
   set refPathList to text items of refPath
   set filePathList to text items of filePath
   repeat with theNodeNum from 1 to (length of refPathList)
      if item theNodeNum of refPathList ≠ item theNodeNum of filePathList then
         set relativePath to ".." & "/" & items theNodeNum thru -1 of 
filePathList
         exit repeat
      end if
   end repeat
   set AppleScript's text item delimiters to oldTIDS
   return relativePath
end getRelativePath
-------------------------------------------------------------------------------------------

This is not pretty, but it's uber-fast.  (I've left error-checking to you.)

No doubt it's similar to what you've built for yourself.

You've got the choose-file part of the script under control?

My personal preference is to avoid choose-file/folder dialogs and use the 
Finder to locate files – then script the Finder-selection.  But of course that 
doesn't always fit perfectly with every work-flow.

--
Take Care,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.

Reply via email to