-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/08/26 22:00
# dMod: 2018/08/26 23:13
# Appl: BBEdit, System Events
# Task: Export Find History to a BBEdit Text Document.
# : Includes a regular _expression_ for entry into Find via Cmd-Shift-E
# : to enable finding bracketed search strings via Cmd-G.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @System_Events, @Export, @Find, @History, @Text, @Document
-------------------------------------------------------------------------------------------
try
set shCMD to "
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:$PATH;
plutil -convert xml1 ~/Library/Preferences/com.barebones.bbedit.plist -o -
"
set thePlist to do shell script shCMD without altering line endings
tell application "System Events"
set bbeditPlist to make new property list item with properties {text:thePlist}
tell bbeditPlist to set plistValue to value of property list items of property list items
set collatorList to {}
tell bbeditPlist
set FindDialog_SearchReplaceHistory_Value to value of property list item "FindDialog_SearchReplaceHistory"
tell FindDialog_SearchReplaceHistory_Value
repeat with theRecord in FindDialog_SearchReplaceHistory_Value
tell theRecord
set srchDate to (its SearchDate as «class isot») as string
set srchDate to findReplTIDS("T", " ", srchDate) of me
set srchStr to its SearchString
try
set replStr to its ReplaceString
on error
set replStr to ""
end try
set end of collatorList to srchDate & tab & "FIND: ❰" & srchStr & "❱" & tab & "REPL: ❰" & replStr & "❱"
end tell
end repeat
end tell
end tell
end tell
set AppleScript's text item delimiters to linefeed
set collatorList to collatorList as text
set shCMD to "
export LANG=\"en_US.UTF-8\"
column -t -s$'\\t' <<< " & quoted form of collatorList
set collatorList to do shell script shCMD without altering line endings
bbeditNewDoc(collatorList, true) of me
tell application "BBEdit"
tell front text window
set before its text to "(?<=❰)\\S.*?(?=❱)" & linefeed & linefeed
select characters 1 thru -1 of line 1
end tell
# open find window
# tell find window
# set selection to "(?<=❰)\\S.*?(?=❱)"
# # close
# end tell
end tell
on error e number n
set e to e & return & return & "Num: " & n
if n ≠ -128 then
try
tell application (path to frontmost application as text) to set ddButton to button returned of ¬
(display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
default button "OK" giving up after 30)
if ddButton = "Copy Error Message" then set the clipboard to e
end try
end if
end try
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on bbeditNewDoc(_text, _activate)
tell application "BBEdit"
set newDoc to make new document with properties {text:_text, bounds:{0, 44, 1920, 1200}}
tell newDoc
select insertion point before its text
end tell
if _activate = true or _activate = 1 or _activate = "activate" then activate
end tell
end bbeditNewDoc
-------------------------------------------------------------------------------------------
on findReplTIDS(_find, _replace, _string)
set oldTIDS to AppleScript's text item delimiters
set AppleScript's text item delimiters to _find
set _string to text items of _string
set AppleScript's text item delimiters to _replace
set _string to _string as text
end findReplTIDS
-------------------------------------------------------------------------------------------