(* open@local v.1.00 * written: Sasaki Atsushi * last modified: 2003-12-30T02:38:12+09:00 *) set dfltDlm to AppleScript's text item delimiters set mySite to path to "site" from user domain as string try set AppleScript's text item delimiters to ":" set mySiteLs to every text item of mySite as list tell application "Jedit4" -- begin error process if not (exists document 1) then error "not HMA" set filePath to fileSpec of document 1 as string set filePathLs to every text item of filePath as list repeat with i from 1 to 4 set {mySiteItem, filePathItem} to {item i of mySiteLs as string, item i of filePathLs as string} if mySiteItem is not filePathItem then error "not HMA" end repeat if item 5 of filePathLs is not "hm7" then error "not HMA" if item -1 of filePathLs does not end with ".html" then error "not HTML doc" -- end error process tell document 1 -- begin modified check if modified then display dialog "This document is not saved yet." & return & "Save now?" buttons {"Cancel", "No", "Yes"} default button "Yes" with icon caution set rslt to button returned if rslt is "Cancel" then return false else if rslt is "Yes" then save end if end if -- end modified check -- begin setting hash to current selection set hash to "" set l to length of selection -- to get back selection to before hash search set off to byteoffset of selection set selection to after selection find "id=\"[^\"]+\"" in it with grep and reverse search without wrap around if result then set {hash, AppleScript's text item delimiters} to {selection, "\""} set hash to every text item of hash as list set hash to item 2 of hash as string end if if l = 0 then -- get back selection to before hash search set selection to before byte off else select (bytes off thru (off + l - 1)) end if -- end setting hash to current selection end tell end tell repeat 4 times set filePathLs to rest of filePathLs end repeat if item -1 of filePathLs is "index.html" then set item -1 of filePathLs to "" set AppleScript's text item delimiters to "/" set localURI to filePathLs as string if not hash is "" then set localURI to localURI & "#" & hash as string open location "http://localhost/" & localURI on error errMsg number errNum set AppleScript's text item delimiters to dfltDlm if errMsg is "not HMA" then display dialog "Open HI-MATICal Archives' HTML document and make it frontmost with Jedit4." buttons {"OK"} default button "OK" with icon stop else if errMsg is "not HTML doc" then display dialog "Open HI-MATICal Archives' HTML document and make it frontmost with Jedit4." & return & "(This document may be not HTML)" buttons {"OK"} default button "OK" with icon stop else display dialog errMsg & return & "Error: #" & errNum buttons {"OK"} default button "OK" with icon stop end if end try set AppleScript's text item delimiters to dfltDlm -- EOF