I use this for maintaining my own html files on my disk which contains applescript library documentation and such.
You must download this scripting addition and put it in your /Library/ScriptingAdditons folder
http://homepage.mac.com/tkurita/scriptfactory/software/OSAX/URIEscape/archives/URIEscape-1.3.1.dmg
And by the way - that scriptingfactory site Is the best I ever saw!
You must download and play with / understand this one first. It explains how to create your own kind of url
( mimetype? ) which you can use at your own will and it contains the script which is the foundation for my post.
http://www.macosxautomation.com/applescript/linktrigger/index.html
I have installed a bookmark with the ur:l webpagehelper://com.apple.AppleScript.WebpageHelper?action=3
In the main script in the scripts bundle I have replaced the original code with this:
else if this_value is "3" then
local winUrl
tell application "Safari"
set winUrl to URL of document 1
end tell
if my load_run("EditCurrentWebFileFromBrowserInBBedit.scpt", winUrl) is false then error number -128
and here comes my script which lives in home/Webpage Helper/ (which I made with a routine in the webpage helper app. I then created an alias into the resources bundle of the Webpagehelper.app with quick access. Just to ease the referencing thing.
What follows is my script which lets you edit the current html file in safari.
property main_property : “”
on run
if isAvalidHtmlFileUrl(main_property) then
set myUnescapedUrl to (URI Unescape main_property) as Unicode text
tell application “BBEdit”
activate
open myUnescapedUrl
replace “\n” using “\r” searching in text 1 of text window 1 options {search mode:grep, starting at top:true}
select insertion point before character 1 of text window 1
end tell
else
display dialog myFileUrl & " is not a valid html document"
– display dialog myUnescapedUrl
end if
end run
on isAvalidHtmlFileUrl(theUrl)
local astid
set astid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “:”
if not text item 1 of theUrl is “file” then
set AppleScript’s text item delimiters to astid
return false
end if
set AppleScript’s text item delimiters to “.”
if not text item -1 of theUrl is “html” then
set AppleScript’s text item delimiters to astid
return false
end if
set AppleScript's text item delimiters to astid
return true
end isAvalidHtmlFileUrl
Finally I configure a shortcut key in butler which fires up the bookmark, and that too works great.
I could have done alot more out of it but I just don’t have the time or interest right now.
It is quite easy to make this work with any browser. And I am sorry for this post being such a mess. But I felt
that I couldn’t do it any other way.
Well I hope you find this useful anyway.
McUsr