Thank you very much for all your help! It now works indeed and it is pretty
quick in comparison with my actual solution with another text robot.
set myfile to alias "full HFS file of the file to be searched in"
tell application "BBEdit"
set docRef to open myfile
set foundRec to (find "searchText" searching in docRef options
{starting at top:true})
if (found of foundRec) then
set text of (found object of result) to ¬
"SubstitutionText"
end if
close docRef with saving
end tell
I can hence process a list of aliases with such a quick tool. Maybe the
section in the manual should be updated. I was trying to follow it before
ending in this dead alley... :-)
By the way, this part is surprisingly poor in comparison with the global
quality and pedagogy of this manual. Really impressive. It made me to
understand at least Regex, I have done any attempts in the past but it
never clicked in my mind (I do program in several languages, even if
Applescript is very new for me). THe explanations in that chapter of the
BBEdit manual were illuminating for me. Thank you very much to its authors!
I have not become a RegeX wizard, but it already helps me in many text
transformations.
Thank you very much again.
Best.
Murat
Le mardi 29 juin 2021 à 13:51:40 UTC+7, [email protected] a écrit :
> On 06/29/2021, at 00:37, Murat <[email protected]> wrote:
>
> set result to (find "<title>" searching in ¬
> (alias "full HFS path to my file") ¬
> options {starting at top:true} with selecting match)
>
> if (found of result) then .....
>
> Script debugger tells me, for the last line
> Variable result is undefined.
>
> If I execute with option returning results, the variable is defined but
> its structure does not correspond with what the script given in the manual
> for the replacement part expects as structure...
>
> ------------------------------
>
> Hey Murat,
>
> Do not make a habit of using the result variable in AppleScript. It's too
> mutable and makes debugging more difficult.
>
> When you search a file on disk BBEdit's file search browser is activated,
> and the found result of the AppleScript is omitted.
>
> To get a found result you can do something like this.
>
> ------------------------------
>
> *set* fileAlias *to* *alias* "MyHD:Users:UserName:Downloads:Test.ccs.txt"
>
> *tell* *application* "BBEdit"
> *set* docRef *to* *open* fileAlias
> *set* foundRec *to* (*find* "Now.+" searching in docRef options {starting
> at top:*true*, search mode:*grep*}) # with selecting match
> *end* *tell*
>
> ------------------------------
>
> To use this script you have to change the path to the file.
>
> Let's make that just a bit more turnkey.
>
> ------------------------------
>
> *set* fileAlias *to* *alias* ((*path to* *downloads folder* as *text*) &
> "Test.ccs.txt")
>
> *tell* *application* "BBEdit"
> *set* docRef *to* *open* fileAlias
> *set* foundRec *to* (*find* "Now.+" searching in docRef options {starting
> at top:*true*, search mode:*grep*}) # with selecting match
> *end* *tell*
>
> ------------------------------
>
> Now if we have the file with the same name in the same relative location
> there is no need to change the path.
>
> You could also write that using a Unix style relative path. BBEdit
>
> ------------------------------
>
> *set* filePath *to* "~/Downloads/Test.ccs.txt"
> *tell* *application* "System Events" *to* *set* fullFilePath *to* POSIX
> path *of* *disk item* filePath
>
> *tell* *application* "BBEdit"
> *set* docRef *to* *open* fullFilePath
> *set* foundRec *to* (*find* "Now.+" searching in docRef options {starting
> at top:*true*, search mode:*grep*}) # with selecting match
> *end* *tell*
>
> ------------------------------
>
>
> --
> Best Regards,
> Chris
>
>
--
This is the BBEdit Talk public discussion group. If you have a feature request
or need technical support, please email "[email protected]" rather than
posting here. Follow @bbedit on Twitter: <https://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 view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/208eaa21-14cc-4761-8808-ad36dcc3b3b3n%40googlegroups.com.