Re: Help browser font size, code timing, RegEx
Re: Help browser font size, code timing, RegEx
- Subject: Re: Help browser font size, code timing, RegEx
- From: Harald E Brandt <email@hidden>
- Date: Sat, 10 Mar 2001 21:29:07 +0100
Thanks everybody for the many clever responses to the issue!
Also fun play with AppleScript! (And below I show my script version...)
Although I can use these solutions, those who *really* would need it most - complete novices and old people with less than perfect sight - are out of reach of such tricks! I noticed that I wasn't alone being "less than satisfied" with Help Viewer...
As I wrote privately to two responders:
I am simply astonished, stunned, amazed and perplexed, that Apple of all companies, makes a help-file reader with tiny teeny small fonts that can't be customized, in an operating system where just about *everything* else is nicely customizable!!??
In IExplorer, I just hit cmd+. In Acrobat, I just zoom, the whole OS offers me to choose the fonts of file listings and menus, I can make almost everything to my taste, *except*..... those tiny help files, despite they are mostly targeted towards the novices! Despite it's basically an html reader!
I wonder what old people think!? Although they would use a different monitor resolution than I have, I am sure my old mother (85) would find those files *very* hard to read!!
Those html files use size 2, i.e what Windoze people often set in their code, which earlier was a big problem. With IExplorer 5 it is no longer a problem since it can render on a 96 dpi grid and offers easy font-zooming. Traditionally, size 3 was considered the standard size for "medium" in simple html files.
==>
Now to AppleScript: We discovered that simply changing the browser was of limited use (because of special script links). Nigels version of changing the font size in all the files was really nice! But since I somewhat dislike fiddling with TIDs, and also think that one should increase SIZE 3 text before increasing SIZE 2, I couldn't refrain from modifying Nigels version to:
on open of theFiles
repeat with eachFile in theFiles
set myFile to open for access eachFile with write permission
set myString to (read myFile)
set myString to REReplace myString pattern "SIZE=\"4\"" with "SIZE=\"5\""
set myString to REReplace myString pattern "SIZE=\"3\"" with "SIZE=\"4\""
set myString to REReplace myString pattern "SIZE=\"2\"" with "SIZE=\"3\""
set eof of myFile to 0
write myString to myFile starting at eof
close access myFile
end repeat
end open
RegEx manipulations are really fast, and I think so much more elegant than TID fiddlings (although requiring an osax). The above script is much shorter, and in my eyes easier to grasp because it is more terse, and lastly lends itself to easy extension with several REReplace lines.
I timed the above version (but with only SIZE 2 -> SIZE 3 replacement), which we can call the "RegEx-version", on files up to 300 kB, and compared it with Nigels original TID-version, and the result is:
They are almost identically fast, with a slight advantage for RegEx. However, at close to 300 kB, the TID version got out of memory and destroyed/garbled the file! (With 2 MB memory allocation to droplet.) The Regex version worked up to about 350 kB before memory problems, and above that it terminated nicely without destroying the file.
In addition, you can make the replacement much safer with the RegEx method: To be precise, you need to ensure that the SIZE string really only is within the html code and not within the text. Increased safety can be achieved with RegEx thus:
set myString to REReplace myString pattern "(<FONT.*)(SIZE=\"2\")(.*>)" with "\\1SIZE=\"3\"\\3" ignoreCase true
(It ensures that the SIZE="2" must be within angle brackets starting with FONT. The above code is supposed to be one line. The whole font tag must be on the same line in the html file for this to work, but I guess violation to that rule is extremely rare.)
But PLEASE: could anyone explain to me why the last "case" thing gets translated to
'with ignoreCase' when the script is saved or checked, whereas it *refuses* to accept
'with ignoreCase' on subequent saves?? Very irritating!...
What is the workaround?
Best Regards, and thanks for your engagement,
PS: I used both "the ticks" (from Jon's Commands) and "time of (current date)" for my timings. The latter is so coarse because it only gives seconds, but the former is quite noisy and unpredictable. The two methods are not always consistent. What *is* really the best way to time things around one or a few seconds? DS
______heb________________________________________________________________
Harald E Brandt email@hidden PGP/MIME aware
http://heb.surf.to