Automator Search and Replace

256 views
Skip to first unread message

Brian R. Wells

unread,
Jun 14, 2013, 12:40:57 PM6/14/13
to bbe...@googlegroups.com
Hey Everyone,

I'm a total newbie to BBedit. 

I downloaded the demo version of BBedit to see if it can do what I need. So far, it can't but I think I am using it wrong.

I am creating an Automator workflow to, Get Finder Names (Finder Action), then Search and Replace (BBedit Action). When I run the workflow with 1 or many files, and the text i want to search for and the text i want to replace it with, the workflow says the actions are completed, but the file has not changed.

For example: I want to search certain .php files for "xCity", and replace with "Gilbert".

Any ideas why BBedit or my workflow isn't changing the .php file?

Thanks in advance for any help.

-Brian

Christopher Stone

unread,
Jun 14, 2013, 8:23:54 PM6/14/13
to bbe...@googlegroups.com
On Jun 14, 2013, at 11:40, Brian R. Wells <brw...@gmail.com> wrote:
I am creating an Automator workflow to, Get Finder Names (Finder Action), then Search and Replace (BBedit Action). When I run the workflow with 1 or many files, and the text i want to search for and the text i want to replace it with, the workflow says the actions are completed, but the file has not changed.
______________________________________________________________________

Hey Brian,

I'm confused about what you're trying to do.

Above you suggest that you want to rename files in the Finder.

For example: I want to search certain .php files for "xCity", and replace with "Gilbert".

Here it seems you want to change content of files in the Finder.

Any ideas why BBedit or my workflow isn't changing the .php file?

Since you haven't provided your workflow for us to see - no.  :)

If you want to replace text within files then you're probably better off using BBEdit's Multi-File Search (Cmd-Shift-F or item 2 in the Search Menu).

Or you may want to consider using a BBEdit Text-Factory if you want to create a reusable action.

If I'm guessing incorrectly about what you're trying to do then please clarify.

--
Best Regards,
Chris


Rich F

unread,
Jun 15, 2013, 2:04:17 PM6/15/13
to bbe...@googlegroups.com
Create a search in the finder with your parameters, then use this to change filenames:


BBEdit isn't what you're looking for.  

Patrick Woolsey

unread,
Jun 15, 2013, 3:19:30 PM6/15/13
to bbe...@googlegroups.com
At 11:04 -0700 06/15/2013, Rich F wrote:
>Create a search in the finder with your parameters, then use this to
>change filenames:
>
>http://www.mrrsoftware.com/MRRSoftware/NameChanger.html
>
>BBEdit isn't what you're looking for.


Sorry but you've misinterpreted what the original poster needs to do, which
is to modify content *within* files:

>On Friday, June 14, 2013 12:40:57 PM UTC-4, Brian R. Wells wrote:
[...]
>For example: I want to search certain .php files for "xCity", and replace
>with "Gilbert".

and that's certainly a job he can use BBEdit to do. :-)


Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com/>

J Hall

unread,
Sep 10, 2015, 11:53:43 AM9/10/15
to BBEdit Talk, pwoo...@barebones.com
Ok, I am trying to do this as well. Except, Several of the items I want to remove, essentially replace with null

So here are my Automator Action Steps:

Get Specified Finder Items
Open Files in BBEdit
Get Contents of BBEdit Document (Set to Front Document)
Search and Replace
Search: </span>
Replace:

It goes through, but even when I'm telling it to use grep, or even replace all title=" with alt=" it doesn't seem to work.

Can anyone help? 

Christopher Stone

unread,
Sep 10, 2015, 4:13:04 PM9/10/15
to BBEdit-Talk Talk
On Sep 10, 2015, at 09:58, J Hall <jha...@gmail.com> wrote:
So here are my Automator Action Steps:
______________________________________________________________________

Hey There,

Automator.  Ugh...  :)

It goes through, but even when I'm telling it to use grep, or even replace all title=" with alt=" it doesn't seem to work.

I don't think you want to be opening each document and doing your find-replace actions.

Better to do something like this:

-------------------------------------------------------------------------------------------
# Find/Replace in all text files in a directory WITH recursion.
-------------------------------------------------------------------------------------------

set searchFolder to "/test_directory/BBEdit_Text_File_Test/"

tell application "BBEdit"
  replace "John \\w+" using "•••••" searching in searchFolder options {search mode:grep, case sensitive:false} with text files only and saving # without recursion
  replace "now.+?time" using "*****" searching in searchFolder options {search mode:grep, case sensitive:false} with text files only and saving # without recursion
end tell


-------------------------------------------------------------------------------------------
# Find/Replace in specific files using posix paths WITH recursion.
-------------------------------------------------------------------------------------------
set fileList to {"~/test_directory/BBEdit_Text_File_Test/test_folder_01/bbedit_test_file_005.txt", "~/test_directory/BBEdit_Text_File_Test/test_folder_01/bbedit_test_file_006.txt", "~/test_directory/BBEdit_Text_File_Test/test_folder_01/bbedit_test_file_007.txt"}
set homeFolderPosix to POSIX path of (path to home folder)

# This loop only necessary if using home-path notation.
repeat with i in fileList
  if contents of i starts with "~/" then
    set contents of i to homeFolderPosix & text 3 thru -1 of (contents of i)
  end if
end repeat

tell application "BBEdit"
  replace "carpenter" using "•••••" searching in fileList options {search mode:grep, case sensitive:false} with text files only and saving # without recursion
  replace "untitled" using "*****" searching in fileList options {search mode:grep, case sensitive:false} with text files only and saving # without recursion
end tell


-------------------------------------------------------------------------------------------
# Find/Replace in selected files in the Finder WITH recursion.
-------------------------------------------------------------------------------------------

tell application "Finder" to set fileList to selection as alias list

if fileList ≠ {} then
  tell application "BBEdit"
    replace "good" using "•••••" searching in fileList options {search mode:grep, case sensitive:false} with text files only and saving # without recursion
    replace "men" using "*****" searching in fileList options {search mode:grep, case sensitive:false} with text files only and saving # without recursion
  end tell
end if

-------------------------------------------------------------------------------------------

If you'll give me a better idea of the file structure you're working with, I'll give you a more specific script.

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages