On Oct 02, 2014, at 08:46, Jakob Peterhänsel <[email protected]> wrote:
> I would like to create files where placeholders is replaced with data from
> parts of a line.
______________________________________________________________________
Hey Folks,
The Satimage.osax makes this kind of job a walk in the park, so my first run at
it has that dependency.
I will post a 100% vanilla AppleScript later today.
--
Best Regards,
Chris
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2014/10/02 11:45
# dMod: 2014/10/03 11:58
# Appl: BBEdit
# Task: Create files from data in BBEdit
# Libs: None
# Osax: Satimage.osax { http://tinyurl.com/dc3soh }
# Tags: @Applescript, @Script, @BBEdit, @Satimage, @OSAX, @Create, @Files
-------------------------------------------------------------------------------------------
property _template : text 2 thru -1 of "
IP1 : %IP1%
Host1 : %HN1%
DATA :
%D1%
"
-------------------------------------------------------------------------------------------
try
set _data to bbeditNamedDocText(1) # Read data from the front BBEdit document.
if _data = "" then error "No data found in front BBEdit document!" # Error
condition.
set _data to cng("^\\A\\s+|\\s+\\Z", "", _data) of me # Strip any vertical
leading or trailing whitespace.
set dataList to fnd("^.+$", _data, true, true) of me # Read data lines into a
list
if dataList = {} then error "Problem at dataList. No data found!" # Error
condition.
# Data Processing
repeat with ndx from 1 to length of dataList
set _temp to _template
set {IP1, HN1, D1} to splittext (item ndx of dataList) using "[[:blank:]]"
with regexp
set _temp to cng("%IP1%", IP1, _temp) of me
set _temp to cng("%HN1%", HN1, _temp) of me
set _temp to cng("%D1%", D1, _temp) of me
writetext _temp to "~/Desktop/yourFileSpec_" & ndx & ".txt"
end repeat
on error e number n
set e to e & return & return & "Num: " & n
if n ≠ -128 then
try
tell current application 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" then set the clipboard to e
end try
end if
end try
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on bbeditNamedDocText(_document)
return application "BBEdit"'s document _document's text
end bbeditNamedDocText
-------------------------------------------------------------------------------------------
on cng(_find, _replace, _data)
change _find into _replace in _data with regexp without case sensitive
end cng
-------------------------------------------------------------------------------------------
on fnd(_find, _data, _all, strRslt)
try
find text _find in _data all occurrences _all string result strRslt with
regexp without case sensitive
on error
return false
end try
end fnd
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
# Bonus Handler
-------------------------------------------------------------------------------------------
--» fndUsing()
-------------------------------------------------------------------------------------------
-- Task: 'Find Text' with Capture using Satimage.osax
-- dMod 2014/08/08 23:05
-------------------------------------------------------------------------------------------
on fndUsing(_find, _capture, _data, _all, strRslt)
try
set findResult to find text _find in _data using _capture all occurrences
_all ¬
string result strRslt with regexp without case sensitive
on error
false
end try
end fndUsing
-------------------------------------------------------------------------------------------
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.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 post to this group, send email to [email protected].