[TxMt] Open Safari source code in TM via Applescript

geibler at gmx.net geibler at gmx.net
Tue Sep 20 08:47:54 UTC 2005

I tried to write an applescript that opens the source code of the  
frontmost Safari window in TextMate (that what happens when you press  
Cmd-Alt-U in Safari, but with TM instead of the internal viewer). So,  
I asked in the IRC how to open a file in TextMate via Applescript. I  
was told that TM does not support Applescript and I should curl the  
source and open that via open -a instead.

Well, this would work, but for my simple purpose, it could be done  
easier; I mean, we got the source already in Safari, so why start a  
curl download?

After some try and error, I found out that the command line tool tm  
is all I need:

-- Script start --
tell application "Safari"
     set mySource to the source of document 1 as string
end tell
do shell script ("echo " & quoted form of mySource & " | /usr/local/ 
bin/tm -a")
-- Script end --

tm must be installed in /usr/local/bin to work in this script. This  
echos the source code into a file in /tmp and opens it in TM. I  
binded it to my Hotkey-App and open it via Cmd-Alt-U in Safari. Works  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20050920/1e04de11/attachment.html>

More information about the textmate mailing list