Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Using BBEdit to work on system files UNIX
No need to learn vi or pico to edit system files, you can use the great BBEdit editor to work on system text files.

Read the rest of this article if you'd like to make it easy to open BBedit from the terminal to work on system files! Thanks to Marc L. for submiting this tidbit!

Type in these commands in a shell, exactly like they are listed here (It's best to copy/paste them):
  1. sudo mkdir /usr/local/bin/
    It's OK if it says "File exists". Type in the adminstrator password when asked.
  2. sudo echo #!/bin/sh >> /usr/local/bin/bbopen
  3. sudo echo open -a '"/Applications/BBEdit/BBEdit 6.1 for OS X"' $* >> /usr/local/bin/bbopen
  4. sudo chmod 755 /usr/local/bin/bbopen
  5. rehash
This assumes you installed BBEdit into the default location, otherwise you need to change line 3. Now you can type the command bbopen followed by the name(s) of the file(s) you want to open.

Example: bbopen /etc/motd will open the file /etc/motd in BBEdit.
If you need to edit files which are owned by the superuser, you can type sudo before bbopen, but be very careful when you do this.

BTW, this also works with the TextEdit application that's included in Mac OS X:

open -a TextEdit filename will open filename in TextEdit.
    •    
  • Currently 3.00 / 5
  You rated: 3 / 5 (3 votes cast)
 
[7,217 views]  

Using BBEdit to work on system files | 15 comments | Create New Account
Click here to return to the 'Using BBEdit to work on system files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Error
Authored by: Tablespork on Apr 23, '01 09:45:39PM

For step 2 I get this:
/bin/sh: Event not found.
I entered it exactly!



[ Reply to This | # ]
Error on second command
Authored by: Anonymous on Apr 23, '01 10:29:05PM

I rejoiced to see the carbon version of BBEdit available this weekend. I would love to get this working however I'm getting the following error form the second command:

bash: !/bin/sh: event not found

Please advise.

Thanks,

m.



[ Reply to This | # ]
What worked for me
Authored by: foster on Apr 23, '01 10:46:05PM

It's easier to just make the script yourself.
>cd /usr/local/bin
>sudo -s (to become root, enter your password)
then you need to create a file, I prefer emacs
>emacs bbopen
this is a very simple script, just write two lines:

#!/bin/sh
open -a '"/Applications/BBEdit/BBEdit 6.1 for OS X"' $*
then
>chmod 755 /usr/local/bin/bbopen
then type C-x C-s to save and C-x C-c to quite emacs

Your final step is you must exit from being root and when you're yourself again, type
>rehash

I think this should you mortolan too- I'm pretty sure it's the same command to start a script under the BASH shell.

I don't know what was wrong with the echo syntax that was posted, but I'm new to this myself.



[ Reply to This | # ]
Almost ...
Authored by: Anonymous on Apr 24, '01 12:38:18AM

The "rehash" command didn't work for me.
Got: bash: rehash: command not found The script works, but I also get the following just before BBEdit launches:
kCGSErrorNoneAvailable : CGSReorderWindows: error retrieving current process

[ Reply to This | # ]

TCSH did the trick
Authored by: Anonymous on Apr 24, '01 12:47:48AM

OK, so I follwed the instructions in TCSH, and 'rehash' worked, but I'm still getting:
"kCGSErrorNoneAvailable : CGSReorderWindows: error retrieving current process"
before BBEdit opens the file I've indicated. Is this normal?

Thanks again,

m.



[ Reply to This | # ]
Drag those commands!
Authored by: thinkyhead on Apr 24, '01 02:26:58AM

I found that I can drag the selected text from Internet Explorer into my terminal - saving the step of copying and pasting! Next time just separate those commands with semicolons and I could do it all with one drag and drop!



[ Reply to This | # ]
still struggling
Authored by: Chas on Apr 24, '01 10:04:20AM
I tried foster's suggestion and created the script using pico. Alas, it still won't run. I made sure that BBEdit was at the proper path, and even if I sudo bbopen, I still get this error:
LSOpenFromURLSpec() returned -10814 for application "/Applications/BBEdit/BBEdit 6.1 for OS X" path /etc/motd.

[ Reply to This | # ]
Sorry for the mess
Authored by: liyanage on Apr 24, '01 03:50:27PM

I have no idea why this worked on my system, I tested it over and over before posting it. Now I just read the comments and tried it on a fresh OS X install and it doesn't work right.

Anyway, here are better instructions:

  1. In a terminal window, type sudo mkdir -p /usr/local/bin
  2. type sudo touch /usr/local/bin/bbopen
  3. type sudo chmod 755 /usr/local/bin/bbopen
  4. type rehash
  5. type sudo open -a TextEdit /usr/local/bin/bbopen

Note: Make sure TextEdit is not running before you type line 5, otherwise it will not run with the rights of the superuser. This seems to cause the kCGSErrorNoneAvailable error message.

TextEdit will open up with an empty window. If it's not empty because of previous attempts, clear anything in the window

Now copy these two lines into the empty document:

#!/bin/sh open -a "/Applications/BBEdit/BBEdit 6.1 for OS X" $*

Save the document and quit TextEdit

It should work now... Let me know if it doesn't.



[ Reply to This | # ]
Got it!
Authored by: Chas on Apr 24, '01 04:56:39PM

Thanks, the new version worked. The problem was the quotation marks, the original example had an extra set of single quotes. Once this was fixed, the script ran beautifully.



[ Reply to This | # ]
skip the script, use shell alias
Authored by: Anonymous on Apr 26, '01 01:07:15AM

make a new file called ".login" in your home directory
.login is a file whose commands run whenever you start a shell session...
in this file enter this:

alias bbopen "open -a '/Applications/Path/To/BBEdit 6.1 For OS X'"

and save it.

then open a new terminal window, and voila, it is available to you
you will even be able to type bb<tab> and the shell will expand it for you.

this should work with most shells. it will definitely work for the default tcsh shell, but others might need a little tweaking.



[ Reply to This | # ]
sudo in 10.1 doesn't give BBEdit root access
Authored by: j0nathan on Oct 24, '01 10:48:33AM

I've used a variation of this script further down the page. However, it seems in 10.1 the command "sudo bbopen" no longer gives BBEdit root access to files subsequently opened. Has anyone else experienced this?



[ Reply to This | # ]
sudo in 10.1 doesn't give BBEdit root access
Authored by: dws on Oct 27, '01 12:04:52PM

doesn't work for me either. the following does work with TextEdit though.

cd /Applications/TextEdit.app/Contents/MacOS/TextEdit
sudo open -a ./TextEdit /System/Library/StartupItems/Mysql/Mysql

File Mysql is owned by root. This doesn't work with BBedit. When trying to edit with BBedit it pops up a dialog saying this file is owned by root. And the file is locked.

dw



[ Reply to This | # ]
The security fix
Authored by: jimr on Oct 28, '01 02:35:54AM

If you have applied the security fix to your 10.1 system, the sudo can not open GUI apps with root privileges.

Bummer....

There is a new version of Pseudo that works around this problem.

So you may continue the editing an execution of GUI apps as root user.

Be advised this is not recommended and is considered to be a risk, as you may then do possible damae to your system.

However, using those CLI editors is like brain surgery in the dark.

Well, guess what, I have seen the New BBEdit 6.5 and it has one fantastic feature among many.

The unlock file icon now is fully functional and when you try to save a file with root permissions it prompts you for your password. Even more, until you close the file... you may continue to save changes without re-inputting your password.

This behavior is much more desireable and you can still open bbedit and file by sudo.

So try your scripts with one of these ways instead.




[ Reply to This | # ]
It gets better...
Authored by: j0nathan on Oct 31, '01 01:39:45PM

BBEdit 6.5 also comes with Unix Tools that when installed allow BBEdit to, amongst other things, be opened via the comand line without going through someof the pain above.



[ Reply to This | # ]
Use 'bbedit' cml tool!
Authored by: marook on Jan 19, '03 11:09:07PM

Hi All.

If you got BBEdit 7.x, just install the commandline tool 'bbedit'. No need to make all the other workarounds!



[ Reply to This | # ]