Switching between BBEdit and Textmate

7 views
Skip to first unread message

Nevan King

unread,
Sep 25, 2008, 4:36:39 AM9/25/08
to BBEdit Talk
Hi all

Sorry if this has been asked before, I couldn't find it in the
archives.

Is there a quick way to quickly switch editing a file between BBEdit
and Textmate? For example, if I'm editing a file in BBEdit and I want
to open the same file in Textmate, usually I'll drag the icon from the
menubar onto the Textmate icon, then save when I finish and go back to
BBEdit. I'd find this easier if I could set up a shortcut key (even
better if I could do it in both BBEdit and Textmate). The way you can
switch editing between Photoshop and Illustrator is a good example.

Thanks

Nevan

Lewis@Gmail

unread,
Sep 25, 2008, 4:28:48 PM9/25/08
to bbe...@googlegroups.com
On 25-Sep-2008, at 02:36, Nevan King wrote:
> I'd find this easier if I could set up a shortcut key (even
> better if I could do it in both BBEdit and Textmate).


I would think it would be pretty trivial to write an applescript and
bind it to a key combo.

--
"Katrina, $4 gas, a trillion dollar war, rising unemployment,
deregulated housing market, global warming...NO MORE!"
http://is.gd/2mxY

Simdude

unread,
Sep 25, 2008, 3:55:09 PM9/25/08
to BBEdit Talk
Can you send the filename of the current document to a shell script?
If so
I'm thinking you could create a small script that runs the "mate"
command to
open the file. You could then bind a keystroke to this script.

From the TextMate side, you could do something similar but call bbedit
with
the filename as the argument.

Would something like this work? (I didn't have time to play with it
yet)

Nevan King

unread,
Sep 29, 2008, 1:37:57 AM9/29/08
to BBEdit Talk
Thanks for the help.

Unfortunately I don't know about scripting for BBEdit. I guess there's
no quick fix, so I'll just keep saving and tabbing between them for
the moment.

Thanks again.

Maarten Sneep

unread,
Sep 29, 2008, 11:47:51 AM9/29/08
to bbe...@googlegroups.com
On 25 sep 2008, at 10:36, Nevan King wrote:

> Is there a quick way to quickly switch editing a file between BBEdit
> and Textmate? For example, if I'm editing a file in BBEdit and I want
> to open the same file in Textmate, usually I'll drag the icon from the
> menubar onto the Textmate icon, then save when I finish and go back to
> BBEdit. I'd find this easier if I could set up a shortcut key (even
> better if I could do it in both BBEdit and Textmate). The way you can
> switch editing between Photoshop and Illustrator is a good example.

This AppleScript will switch from BBEdit to TextMate:

(* Script to switch a document from BBEdit to TextMate.
Written by Maarten Sneep, 2008. Enjoy *)

tell application "BBEdit"
-- save the active document
if (modified of active document of window 1) then
save active document of window 1
end if
-- get path of active document
set mypath to get file of active document of window 1
-- get line number of insertion point
set theSelection to selection
set theline to (startLine of selection)
-- Hope that 'mate' is installed in a location that is in the
standard path.
-- if sh complains, use full path here.
-- assumes mate can be called with a +linenumber argument to set the
active line.
do shell script "mate +" & (theline as string) & " " & quoted form of
(POSIX path of mypath)
end tell

-- end script

Copy and paste the script text in the Script Editor, and save the
compiled script in ~/Library/Application Support/BBEdit/Scripts//.
Keyboard shortcuts can be added from the Scripts Palette in the
Windows menu.

I don't know anything about scripting TextMate, you'll have to ask
elsewhere. The shell command "bbedit +linenumber file" is available.
Hope this helps.

Maarten

Lee Hinde

unread,
Sep 30, 2008, 5:09:30 PM9/30/08
to bbe...@googlegroups.com
I changed the last line as follows:
do shell script "/usr/local/bin/mate  " & quoted form of (POSIX path of mypath)

Sending the line number just confused TextMate.

Thanks for this!




Maarten



Maarten Sneep

unread,
Sep 30, 2008, 5:45:51 PM9/30/08
to bbe...@googlegroups.com
On 30 sep 2008, at 23:09, Lee Hinde wrote:

> I changed the last line as follows:
> do shell script "/usr/local/bin/mate " & quoted form of (POSIX
> path of mypath)
>
> Sending the line number just confused TextMate.

Ah, mate does not use the syntax pretty much _every_ other editor uses
(vi, emacs, nedit, bbedit), but wants this in another optional
argument. This should work:

do shell script "/usr/local/bin/mate -l " & (theline as string) & " "

& quoted form of (POSIX path of mypath)

Maarten

Lewis@Gmail

unread,
Sep 30, 2008, 7:55:04 PM9/30/08
to bbe...@googlegroups.com

Odd that mate uses a different syntax from bbedit.

Nevan King

unread,
Oct 2, 2008, 1:50:06 AM10/2/08
to BBEdit Talk
Thanks so much Maarten! I'm using it now.

I had to install the mate command as described here
http://manual.macromates.com/en/using_textmate_from_terminal.html

and unwrap some of the comment lines in your script to make the
compiler happy, but other than that it was really easy. once i added
Lee's fix for line number and it works like magic.

Thanks again!

Nevan

Nevan King

unread,
Oct 2, 2008, 2:44:40 AM10/2/08
to BBEdit Talk
I poked around the bundle editor in textmate and came up with this:

#!/bin/sh
# Open the current file in BBEdit
bbedit +$TM_LINE_NUMBER $TM_FILEPATH

I saved it as a command with settings (top to bottom)
Save: Current File
Input: Entire Document
Output: Discard
Key Equivalent: my shortcut key
selector: source.php (means it only works in php files)

It opens the file at with the line number you were working on selected
(copied that from above)

Thanks again to everyone for all the help with this.
Reply all
Reply to author
Forward
0 new messages