Shell script to make BBEdit the default text editor for 'open -t' and LaunchServices

421 views
Skip to first unread message

TJ Luoma

unread,
Jul 25, 2018, 10:41:25 AM7/25/18
to BBEdit Talk

I was looking for a way to make BBEdit the default text editor for _all_ text files. 

More specifically, I wanted to be able to use 'open -t' and have the file open in BBEdit.

Just to refresh your memory, quoting from `man open`:

     -t  Causes the file to be opened with the default text editor, as determined via LaunchServices

I went searching on the web for this, but 99% of what I saw came down to "Select the file in Finder, choose 'Get Info' and tell it to 'Change All' of those file extension types to open with BBEdit!' Of course that wasn't helpful because I already knew that, but what about files with _no_ extension? And what about 'open -t'? 

Finally I came across a StackOverflow answer (https://stackoverflow.com/questions/9370584/set-textmate-as-the-default-text-editor-on-mac-os-x) which gave me enough of an answer that I was able to adapt it for BBEdit.

In case anyone else is curious, here is the command that I used:

defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.barebones.bbedit;}'

After that, I used `open -t ~/.ssh/authorized_keys` and the file opened in BBEdit. I didn't even have to logout/login or reboot, as some had suggested.

(This was in the public beta 3 of Mojave, FWIW.)

I hope this might be of use to someone else… or possibly me, in the future, when I search the web for the answer to this question and find my own answer to it ;-)

Tj


@lbutlr

unread,
Jul 25, 2018, 4:31:00 PM7/25/18
to BBEdit Talk
On 25 Jul 2018, at 08:41, TJ Luoma <luo...@gmail.com> wrote:
> defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
> '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.barebones.bbedit;}'

It does not appear to work in beta 4.


Bruce Van Allen

unread,
Jul 25, 2018, 5:37:18 PM7/25/18
to bbe...@googlegroups.com
On 7/25/18 at 1:30 PM, kre...@kreme.com (@lbutlr) wrote:
>defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
>'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.barebones.bbedit;}'
>
>It does not appear to work in beta 4.
>

Just checking: you might need to log out and back in again.
--

- Bruce

_bruce__van_allen__santa_cruz__ca_

Reply all
Reply to author
Forward
0 new messages