Hi,
I do not know whether this is interesting for other users as well, but I find it's worth to have a small note on it.
Up to now TM doesn't have the chance to do something when it starts. But there is an easy way to trigger a tmCommand or whatever.
A concrete example: I want to open TM and it should start Rdaemon automatically.
Solution: I wrote a tiny AppleScript with Script Editor:
tell application "TextMate" activate tell application "System Events" to keystroke "r" using {control down,command down,option down} end tell
and I save it as an application with the name "TM_Rdaemon" (if you want, customize the icon ;). Now you put this app to any location or drag'n'drop it to the Finder's toolbar.
If you invoke TM_Rdaemon.app it starts TM and it executes the key combo CTRL+OPTION+APPLE+R which is a shortcut to open Rsession.proj and to start Rdaemon.
To generalize it a bit one can also use this simple approach to trigger a auto-start-up script. The only thing to do is to create a tmCommand, let's say AUTOSTART, with the desired commands you want to call after TM started and bind it to a UNIQUE key combo without setting a scope. After doing it, change the above mentioned AppleScript and change ...to keystroke ... to your UNIQUE key combo. Then you can change the AUTOSTART tmCommand easily to trigger some stuff, e.g. open the Bundle Editor and open a specific project or whatever; or open a file and set it to specific grammar language. Everthing is done by using AppleScript's '"System Events" to keystroke'.
At least for me, it saves sometimes a bit time.
[BTW Is this worth to mention it in TM's wiki "How to > AppleScript" ?]
Cheers,
--Hans
Hi,
of course, my tiny approach only works if TM opens at least one document window at startup. Thus I changed the code a bit for the general solution:
[assuming that the AUTOSTART tmCommand has the unique key combo ctrl +shift+opt+apple+a]
try tell application "TextMate" activate set n to count of (every window where visible is true) set flag to 0 repeat with x from 1 to n set winName to the name of window x if length of winName < 8 then set winName to "dummmmmy" if length of ((path of (document x)) as text) > 0 or text 1 thru 8 of winName = "untitled" then set flag to 1 exit repeat end if end repeat if flag = 0 then tell application "System Events" to keystroke "n" using {command down} end if tell application "System Events" to keystroke "a" using {control down, command down, option down, shift down} end tell end try
##########
To start Rdaemon even there is no window open, I replaced the tmCommand "Open Rsession" by a tmTemplate "Open Rsession", because a template key combo can be pressed even if there's no window open ;) [is already in the svn repository]
--Hans