Hey Chris!

I’ve just switched priorities (see my previous mail to Rick) regarding RegEx 
and AppleScript and now you put everything in question again! ;-)

Your AppleScript solved my question and even a lot more (loads the TOC directly 
and put the row between the chapters - that Rick’s RegEx forgot)… now I *only* 
have to understand HOW! ;-)
Thanks a lot… but now you’re „in“ for some questions ;-)

1.- I suppose that JavaScript „document_readyState“ must be some DOM-function? 
(I didn’t even know that is it possible to call JavaScript from AppleScript!)

2.- How did the Handler getSafariText now WHICH text to get from the page? Or 
is this magic put in the first *replace*

> 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}
                
?

3.- RegEx remains the priority: I can understand everything that the handlers 
do but not a word of the replace’s! :-/ :-)

4.- In your script everything is local: the „main-program“ and the „routines“. 
a) Is it possible to put handlers outside the script itself (in order to be 
able to call them from various scripts)? and then b) how do you declare the 
global returns used in the - now global - handlers? Or is this a bad idea at 
all to externalize handlers (due to performance / complexity / whatever)?

Thanks, Chris, I’ve learned again a lot - you’re too good to me!


Until next time,
Vlad


P.S. Actually my priority right now is Joomla! - that’s the reason of my visit 
on lynda.com <http://lynda.com/>, the AppleScript-tutorial was only me taking a 
pause from Joomla! ;-) - because I'll probably get a job doing a website where 
I'll probably better use Joomla!… and right now I don’t know anything at all 
about it! :-/ So the RegEx and AppleScript (and a couple of others too like 
using LESS on my yoga-website or making a program to scaling chosen images 
until they have a certain size - something that scratches one of my itches, I 
admit! - etc.) will have to wait, the nights are only so long… :-(


> Am 09.12.2014 um 19:10 schrieb Christopher Stone <[email protected]>:
> 
> On Dec 08, 2014, at 02:03, Vlad Ghitulescu <[email protected] 
> <mailto:[email protected]>> wrote:
>> Copying and pasting the TOC of the "Up and Running with AppleScript 
>> <http://www.lynda.com/AppleScript-tutorials/Up-Running-AppleScript/158309-2.html>“
>>  - tutorial bei Lynda.com <http://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
>  
> <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 <smb://A.+Expand> all \\| <smb://|> Collapse 
> all[[:blank:]]*\\r+(.+(?=\\r{1,}Watch this entire course)).+" using "\\1 
> <smb://1>" options {search mode:grep, case sensitive:false, starting at 
> top:true}
>     replace "\\r(\\d+[ms]) <smb://r(//d+[ms])>" using " \\1 <smb://1>" 
> options {search mode:grep, case sensitive:false, starting at top:true}
>     replace "^(\\d <smb://d>)" using "\\r\\1 <smb://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 
> <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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.

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