On Dec 08, 2014, at 02:03, Vlad Ghitulescu <[email protected]> wrote:
> Copying and pasting the TOC of the "Up and Running with AppleScript“ - 
> tutorial bei Lynda.com leads to this:
> …
> I certainly can do this „manually“, as I did in this email, but I can imagine 
> there’s a more „intelligent“ / efficient way to do this with text factories 
> (or perhaps AppleScript or RegEx?!) therefore my question: how would you 
> solve something like this in BBEdit?
______________________________________________________________________

Hey Vlad,

Manually?  😎

--
Take Care,
Chris

-------------------------------------------------------------------------------------------
set _url to 
"http://www.lynda.com/AppleScript-tutorials/Up-Running-AppleScript/158309-2.html";
loadSafariUrl(_url, true)
SAFARI_PAGE_LOADED(5)
set _text to getSafariText()
bbeditNewDoc(_text, true)
-------------------------------------------------------------------------------------------
tell application "BBEdit"
  tell front text window's text
    replace "(?s)\\A.+Expand all \\| Collapse 
all[[:blank:]]*\\r+(.+(?=\\r{1,}Watch this entire course)).+" using "\\1" 
options {search mode:grep, case sensitive:false, starting at top:true}
    replace "\\r(\\d+[ms])" using " \\1" options {search mode:grep, case 
sensitive:false, starting at top:true}
    replace "^(\\d)" using "\\r\\1" options {search mode:grep, case 
sensitive:false, starting at top:true}
  end tell
end tell
-------------------------------------------------------------------------------------------
--» 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 then activate
  end tell
end bbeditNewDoc
-------------------------------------------------------------------------------------------
on getSafariText()
  tell application "Safari" to return text of front document
end getSafariText
-------------------------------------------------------------------------------------------
on loadSafariUrl(_url, _activate)
  tell application "Safari"
    if _activate = true then activate
    set URL of front document to _url
  end tell
end loadSafariUrl
-------------------------------------------------------------------------------------------
on SAFARI_PAGE_LOADED(timeout_value)
  delay 2
  repeat with i from 1 to the timeout_value
    tell application "Safari"
      if (do JavaScript "document.readyState" in document 1) is "complete" then
        return true
      else if i is the timeout_value then
        return false
      else
        delay 2
      end if
    end tell
  end repeat
  return false
end SAFARI_PAGE_LOADED
-------------------------------------------------------------------------------------------

-- 
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].

Reply via email to