Automation with BBEdit?

Discussion in 'Mac Basics and Help' started by Texas_Toast, Nov 29, 2018.

  1. Texas_Toast macrumors 6502a

    Texas_Toast

    Joined:
    Feb 6, 2016
    Location:
    Texas
    #1
    Does anyone here have experience using the text editor called BBEdit?

    I have a repetitive task that I would like to automate, and I am wondering if it could be done using BBEdit?
     
  2. techwarrior macrumors 65816

    techwarrior

    Joined:
    Jul 30, 2009
    Location:
    Colorado
    #2
    BBEdit is a text editing app that can be used to write scripts. If you don’t already know scripting languages, you may be better off using Automator or AppleScript editor.
     
  3. Texas_Toast thread starter macrumors 6502a

    Texas_Toast

    Joined:
    Feb 6, 2016
    Location:
    Texas
    #3
    Here is what I am trying to do..

    I need to take some HTML files and replace some of the code based on keywords.

    For starters, if I could open up a blank HTML file in BBEdit, click a button, and it would simply do a "Find and Replace" on the defined keywords that would be a real time saver.

    Of course, being able to just paste in a URL or file name, and click a "Process" button, and having it do the "find and replace" and then saving the file would be even better.

    Having an automation script like this would be a real time saver for me as I need to do tis a couple times a day, however, if I have to send a few months learning a new scripting language, then I'm thinking the return wouldn't be worth it.

    Hope that makes sense, and that maybe there is an easy solution out there.

    (BTW, I have a fair amount of programming experience. Yet while understand coding logic, I am not a professional script writer!)

    Thanks!
     
  4. techwarrior macrumors 65816

    techwarrior

    Joined:
    Jul 30, 2009
    Location:
    Colorado
    #4
    If you know programming, BASH scripting, python, etc should come pretty easy to you.

    I found this on Stack Overflow, seems promising. Using a for loop and sed, you should be able to run a script that inspects all files in a directory, searches for a string or url, and replaces it. If your routine is as simple as defining a string to remove and another to insert, you could create a script to search for *.html in a given directory, and pop up a dialog to prompt for the strings.

    Bash uses a lot of conventions you should already be familiar with, you should be able to pick it up fairly quickly.

    BBEdit is a fine program. You can open multiple files, create a search and replace parameter, and use a couple of keystrokes to run it for each file. The app is free for 30 days with full features, then pro features are disabled unless you buy a license. May be worth a shot to download it and try it out.
     
  5. CreatorCode, Dec 7, 2018
    Last edited: Dec 7, 2018

    CreatorCode macrumors regular

    CreatorCode

    Joined:
    Apr 15, 2015
    Location:
    US
    #5
    BBEdit supports AppleScript automation very thoroughly. See Chapter 13 of the BBEdit User manual.

    You can save an AppleScript to the BBEdit Scripts folder and it will appear as a menu item in the Script menu (fancy scroll-S icon) so that you can call it by selecting it from the menu.

    To automate the find-and-replace command, for example, you'd do something like

    Code:
    tell application "BBEdit"
    
        activate
    
        open find window
    
        replace "text to be replaced" using "desired replacement text" searching in text 1 of
    document 1options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
    
    end tell
    
     
  6. Texas_Toast thread starter macrumors 6502a

    Texas_Toast

    Joined:
    Feb 6, 2016
    Location:
    Texas
    #6
    Is BBEdit worth the $50 they charge?
     
  7. Red Menace macrumors 6502

    Red Menace

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #7
    It depends on your tastes and exactly what you are wanting, but I think it is. I probably run it more than any other application, using it to manage RubyMotion projects, edit and run shell scripts, HTML, Markdown, property lists, etc. As already mentioned, it has extensive AppleScript support, and is pretty much a text editing Swiss Army knife.

    It is also worth noting that after BBEdit's 30-day free trial expires, it will continue to run with features similar to TextWrangler (which has been sunsetted), so even if you don't want the full version, you will still have a decent programming editor.
     

Share This Page

6 November 29, 2018