set local_domain to "simon.local" set site_directory to "Simons HD:Users:simon:Sites" tell application "System Events" -- Find out if Safari is running if not (exists (application process "Safari")) then activate set dialogText to "Safari is not running." display dialog dialogText buttons {"OK"} default button 1 return end if end tell tell application "Safari" -- Find out if Safari has a window open if not (exists (front window)) then activate set dialogText to "No windows are open in Safari." display dialog dialogText buttons {"OK"} default button 1 return else -- Get the URL of the page currently displayed in Safari's front window set current_URL to URL of document of front window end if end tell --things could get messy with escaped chars... catch an obvious one.. set current_URL to SaR(current_URL, "%20", " ") --check to see if the url is alread a file:/// set file_check to subString(current_URL, 1, 8) if (file_check is equal to "file:///") then -- thing just got a little simpler set current_URL to SaR(current_URL, "file:///", "") set volume_check to subString(current_URL, 1, 8) if (volume_check is equal to "Volumes/") then -- the file is on a mounted volume set current_URL to SaR(current_URL, "Volumes/", "") else -- the file should be on the startup disk set current_URL to ((path to startup disk as text) & current_URL) end if else set check_local to SaR(current_URL, local_domain, "iama.localurlsonoworries") -- check_local WON'T be equal to current_URL if it is a local domain if (check_local is equal to current_URL) then display dialog "This isn't the local domain I'm looking for:" & local_domain buttons {"OK"} default button 1 return end if -- convert server Aliases... check httpd.conf for details set current_URL to SaR(current_URL, local_domain & "/books", local_domain & "/misc/books") set current_URL to SaR(current_URL, local_domain & "/php", local_domain & "/misc/php") set current_URL to SaR(current_URL, local_domain & "/photos", local_domain & "/helvector/httpdocs/photo") -- check for querystrings and remove set current_URL to removeTrailing("?", current_URL) -- check for page anchors and remove set current_URL to removeTrailing("#", current_URL) -- replace the http://domain with the site_directory set current_URL to SaR(current_URL, "http://" & local_domain, site_directory) end if -- convert all slashes to colons and isolate the parent (remember fileToShow could actually be a Directory) set current_URL to SaR(current_URL, "/", ":") set current_DIR to removeTrailing(":", current_URL) -- store the file and directory for use by try set fileToShow to alias (current_URL) on error display dialog "The URL wasn't found on the file system " & current_URL return end try set dirToShow to alias (current_DIR) -- Use the file with an app of your choice.... --(* tell application "Finder" -- comment 'activate' in/out if you want the window to appear in the foreground/background --activate -- if you're happy with no window control then just use the following line --reveal fileToShow -- want to see the parent directory instead? --reveal dirToShow -- otherwise config your window settings here... --(* -- window will be 550 wide by 755 high, x at 6 and y at 82 in (column, icon or list) column view tell (open container window of dirToShow) to  set {bounds, current view} to {{6, 82, 650, 750}, column view} reveal fileToShow --*) end tell --*) (* Or Maybe? tell application "BBedit" open fileToShow end tell *) on SaR(aText, asearch, areplace) try set oldAstid to AppleScript's text item delimiters set AppleScript's text item delimiters to asearch set a_text to every text item of aText set AppleScript's text item delimiters to areplace set a_text to (every text item of a_text) as string set AppleScript's text item delimiters to oldAstid return a_text on error return false end try end SaR on lastIndexOf(str, longstr) set lof to (offset of ("" & reverse of str's items) in ("" & reverse of longstr's items)) if lof is 0 then return 0 --> not found return -(count str) + 1 - lof end lastIndexOf on subString(the_string, start_index, end_index) return "" & (get characters 1 thru end_index of the_string) end subString on removeTrailing(last_instance_of, the_URL) set qs to lastIndexOf(last_instance_of, the_URL) if (qs is not 0) then return subString(the_URL, 1, qs - 1) else return the_URL end if end removeTrailing