On 06/28/2021, at 04:35, Paul G <[email protected] 
<mailto:[email protected]>> wrote:
> Would anyone be up to writing a couple of basic scripts for me to use in 
> BBEdit?
> If so let me know price.
> 
> I just need a script to alphabetically sort lines within certain parameters 
> inside a text doc and another to replace certain text within a text doc.


Hey Paul,

Replacing text with AppleScript is easy enough once you know how:

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/06/28 21:28
# dMod: 2021/06/28 21:37
# Appl: BBEdit
# Task: Replace Either RegEx or Literal Text in the Designated BBEdit Window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Replace, @RegEx, @Literal
-------------------------------------------------------------------------------------------

# Use "Front_Text_Window" to Target the Front Window.
# Otherwise use the Window Name as the targetWindow.

# REMEMBER - The backslash for RegEx metacharacters "\" must be escaped in 
AppleScript "\\".

# Verbose:
set matchStr to "Nyet\\s"
set replaceStr to "Da"
set targetWindow to "Front_Text_Window"
set grepFlag to {|regEx|:true}
bbeditReplaceMatchInTargetWindow(matchStr, replaceStr, targetWindow, grepFlag)

# Less Verbose:
# bbeditReplaceMatchInTargetWindow("Nyet\\s", "Da", "Front_Text_Window", 
{|regEx|:true})

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on bbeditReplaceMatchInTargetWindow(matchStr, replaceStr, targetWindow, 
grepFlag)
    
    tell application "BBEdit"
        if targetWindow = "Front_Text_Window" then
            set targetWindowRef to a reference to the front text window
        else
            set targetWindowRef to a reference to text window targetWindow
        end if
        
        if grepFlag's |regEx| = true then
            set searchModeType to grep
        else
            set searchModeType to literal
        end if
        
        # Case-Sensitive is OFF by Default – Switch on using (?-i)
        tell targetWindowRef's text
            replace matchStr using replaceStr options {search 
mode:searchModeType, starting at top:true}
        end tell
        
    end tell
    
end bbeditReplaceMatchInTargetWindow
-------------------------------------------------------------------------------------------

Sorting lines “within certain parameters” requires more explanation.  Please 
provide real world examples.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/5966CF7B-80BF-4D13-871F-96981C854A9D%40gmail.com.

Reply via email to