----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2014/10/29 07:10
# dMod: 2018/09/09 14:04
# Appl: BBEdit
# Task: Find and Replace in Files On-Disk.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Find, @Replace, @Files, @Disk
----------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
----------------------------------------------------------------
# The Search Folder reference can be either an alias or a posix path or a posix file.
set searchFolderPath to "~/test_directory/Find_and_Replace_It_Test/"
if searchFolderPath starts with "~" then
set searchFolderPath to ((current application's NSString's stringWithString:searchFolderPath)'s stringByExpandingTildeInPath) as text
end if
----------------------------------------------------------------
set findStr to "good men"
set replStr to "I want my MTV!"
----------------------------------------------------------------
tell application "BBEdit"
replace findStr using replStr searching in searchFolderPath ¬
options {search mode:grep, case sensitive:false, showing results:false} ¬
saving true ¬
recursion true ¬
with text files only
end tell
----------------------------------------------------------------