----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/05/29 15:00
# dMod: 2018/05/29 15:00
# Appl: BBEdit
# Task: Decode Base64 Segments in front document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Decode, @Base64, @Segments, @Front, @Document
----------------------------------------------------------------
set itemFound to true
tell application "BBEdit"
tell front text window's text
select insertion point before character 1
repeat while itemFound
set findRecord to find "(^[0-9a-zA-z+/]{76}\\r)+.*\\r" options {search mode:grep, case sensitive:false}
if found of findRecord ≠ true then
set itemFound to false
else
select found object of findRecord
set dataStr to contents of text of found object of findRecord
set decodedStr to decodeBase64(dataStr) of me
if decodedStr ≠ dataStr then set contents of selection to decodedStr
end if
end repeat
end tell
end tell
----------------------------------------------------------------
--» HANDLERS
----------------------------------------------------------------
on decodeBase64(dataStr)
set shCMD to "
base64 -D <<< " & quoted form of dataStr
do shell script shCMD
end decodeBase64
----------------------------------------------------------------