gorn.ch

Tobias Ebnöther's personal blog

View source in Safari with TextMate

Some days ago Lukas Smith asked me if it's possible to get source highlighting in Safari. For Firefox I used the ViewSourceWith extension for a long time to use TextMate. So now I wanted to get that in Safari too. Usually I use Safari to browse and Firefox to develop so it's not really necessary but a nice feature.

I found a cool plugin for Safari called SafariScript which ships a view source in TextMate script. But the script is pretty poor. It just fetches the URL via curl to a specified file, so you can only access public sites and only one page at time. The other scripts are very cool trough for example the "Open page in Firefox" script which I love when I opened the page in the wrong browser.

I came up with my own script which you can see bellow. It fetches the source directly from Safari instead of downloading the URL and it adds a timestamp and random number to the tempfile so it should be possible to open as much pages as you want. Just put it in place of the old script and add a cool keyboard shortcut (I use ⌘U as in Firefox).

property newline : ASCII character 10

set timestamp to do shell script ("date +%s") & (random number from 1 to 1024) as text
set tmpfile to POSIX path of ((path to "temp" as Unicode text) & "view_source" & (timestamp) & ".html ")
set tmpfileSpec to ((path to "temp" as Unicode text) & "view_source" & (timestamp) & ".html ") as file specification

tell application "Safari"
        set htmlSource to source of document of front window as text
end tell

set fp to open for access tmpfileSpec with write permission
set eof of fp to 0
write (htmlSource) to fp starting at eof
close access fp

tell application "TextMate"
        activate
        open tmpfileSpec
end tell

do shell script "rm -f  -- '" & tmpfile & "'"
Related Entries:
TextMate Presentation
Comments (5)  Permalink

TextMate Presentation

As mentioned in the post earlier I was going to do a presentation of TextMate. In the final version I excluded the blogging bundle stuff since it doesn't work well with the FluxCMS blog and I was short on time.

If you're still interested you can get the slides here. The slides are something like a mix between feature presentation (first part) and cheatsheet (second part).

There did some interesting things happen while writing this presentation.
1) Presenting a text editor is more stupid than I thought. Actually there are a lot of things that you like and can't explain well in words - it's just a feeling you get.
2) I'm using ways to less key combos :)
3) TextMate rocks!
4) I need to train my presentation skills and try to not forget things I wanted to say (in the correct order)...
Related Entries:
Jackalope presentation and status
View source in Safari with TextMate
Leopard native apache with custom (64bit) PHP
Leopard PHP / Apache Package with pecl support
Nabaztag Widget
 Permalink
1-2/2
Powered by Flux CMS