On Sep 20, 2005, at 19:44 , Fred B. wrote:
On 20 sept. 05, at 18:57, Eric Peden wrote:
On Tue, Sep 20, 2005 at 01:47:49PM +0200, José Campos wrote:
Is it yet, or will it be possible to get a item like this in
Safari->Services : "Edit page source in TextMate"?
Did you see this?
You could use the AppleScript menu to get an actual menu item for it, as
opposed to just having a keystroke. At that point, the only difference
between the AppleScript solution and a service would be which menu it
appeared on. ;)
Here is a more sophisticated version, it saves the source of the front page of Safari in a temp folder then opens it in TM.
If there is no window in Safari or if it's empty, it warns you.
If the name of the page contains slashs, it replaces them with colons.
There's maybe better ways to achieve that, but that's I come up with after encountering numerous problems.
AS is useful but can really suck!
tell application "Safari"
if not (exists document 1) then
display dialog "You need to open a web location first!" buttons {"OK"} default button 1
return
end if
set mySource to the source of front document as text
if (length of mySource is 0) then
display dialog "You need to open a web location first!" buttons {"OK"} default button 1
return
end if
set myName to name of front document as text
end tell
try
tell application "TextMate" to activate
set myName to replace_chars(myName, "http://", "")
set myName to replace_chars(myName, "/", ":")
if (myName ends with ".html") or (myName ends with ".htm") then
set myPath to "/tmp/" & myName
else
set myPath to "/tmp/" & myName & ".html"
end if
do shell script "rm -f " & quoted form of myPath
do shell script "echo " & quoted form of mySource & " >> " & quoted form of myPath
do shell script "open -a TextMate " & quoted form of myPath
end try
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
______________________________________________________________________
(threading gets destroyed and the universe will collapse if you don't)