Advertisement
rccharles

asc preprocesss fixup Solve issues.app

Jul 3rd, 2020
1,709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2.  
  3.   This applescript converts clipboard input into a format suited for pasting into an ASC
  4.   reply.  I observed that my copies into an ASC reply were not formated that well.  
  5.   I observed that copies from a web browser were formated much better.  I went about
  6.    adjusting the clipboard copy to the format expected by a web browser for best results.
  7.  
  8.  This applescript accepts the clipboard in either
  9.  -- plain text upon which the text is converted to HTML.  Conversion is limitted to inserting paragraph tags for blank lines and inserting links where http or https text appears. The page title is substituted for the link.  
  10.  -- HTML source code identified by text containing HTML markup.  
  11.          Caveat emptor.  
  12.  
  13. run with copy from Waterfox. List of main routines.
  14.   --- run ---
  15.   --- common ---
  16.   --- adjustCharacters ---
  17.   --- adjustBrowserHTML ---
  18.   --- adjustURLs ---
  19.   --- skipDoctype
  20.   --- adjustDuplicateAnchorURLs ---
  21.   --- adjustToAscHtml ---
  22.   --- adjustLF ---
  23.   --- convertToHTML ---
  24.  
  25. run with HTML as text from TextWrangler. List of main routines.
  26.   --- run ---
  27.   --- common ---
  28.   --- adjustCharacters ---
  29.   --- adjustBrowserHTML ---
  30.   --- adjustURLs ---
  31.   --- skipDoctype
  32.   --- adjustDuplicateAnchorURLs ---
  33.   --- adjustToAscHtml ---
  34.   --- adjustLF ---
  35.   --- adjustLF ---
  36.   --- adjustLF() ---
  37.   --- convertToHTML
  38.  
  39. run with plain text from TextWrangler. List of main routines
  40.   --- run ---
  41.   --- common ---
  42.   --- adjustCharacters ---
  43.   --- adjustURLs ---
  44.   --- addParagraphs ---
  45.   --- convertToHTML ---
  46.  
  47.  to use:
  48.  1) copy command + c what data you want to convert
  49.  2) run this applascript by double clicking on the app.
  50.  3) paste command + V into an ASC reply
  51.  
  52.  I have tested in Waterfox 56.2.9 in Yosemite.  I assume the process will work with other web browsers and other versions of macOS.
  53.  
  54.  Save as an Application Bundle.  Don't check any of the boxes.
  55.  
  56. Should you experience a problem, run in the Script Editor.
  57.    Shows how to debug via on run path. Shows items added to folder. Shows log statement.
  58.    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.  
  59.    
  60.   For testing, run in the Script Editor.
  61.          1) Click on the Event Log tab to see the output from the log statement
  62.       2) Click on Run
  63.    
  64. change log
  65. may 1, 2019   -- skip 403 forbidding title
  66. may 2, 2019   -- convert \" to ".  the \" mysteriously appears in HTML source code input.  Probably some TextEdit artifact.
  67.                 copy to TextEdit copy out of TextEdit.
  68. may 7, 2019   -- regressed May 2nd update.  Applescript was inserting \" for display purposes into output.
  69. may 8, 2019   -- special processing for html class on clipboard
  70.                          https://pastebin.com/raw/Yg138YqT
  71. may 16,2019  -- fixed hexDumpFormatOne bugs and improved output
  72. may 16,2019  -- added hexDumpFormatZero
  73. may 19,2019  -- eliminate line breaks outside the <pre>...</pre> tags in HTML. ASC intrepreting line
  74.                          breaks as meaningful <br>
  75.                          instead of white space.simplified line break code.
  76.                        https://pastebin.com/raw/Nq08cFYH
  77. may 23, 2019 -- squash leading blanks in a line. #4
  78. may 27, 2019 -- Horizontal Ellipsis. #7
  79.                          8230   U+2026  E2 80 A6    … Horizontal Ellipsis
  80.                  https://www.charset.org/utf-8/9
  81. may 28, 2019 -- decide what to do with tabs. #6
  82. may 29, 2019 -- filter titles. #1
  83.                          https://pastebin.com/raw/3xRYMXtd
  84. june 1, 2019   -- automate debugging
  85. June 8, 2019   -- Substitute title for duplicate links
  86.                          https://pastebin.com/raw/PYb9Bvri
  87. June 14, 2019 -- Substitute title for more duplicate links
  88.                          https://pastebin.com/raw/n2im5Cp5
  89. June 15, 2019 -- ignore DOCTYPE                      
  90. June 17, 2019 -- ignore signin title for lounge posts
  91. June 17, 2019 -- add "if debug" where forgotten
  92. June 18, 2019 -- skip image tags
  93.          
  94.  
  95. enhancements:
  96.   -- get pdf title
  97.   -- ignore <head>
  98.  
  99.  
  100. Author: rccharles
  101.  
  102.  Copyright 2019 rccharles  
  103.      
  104.        Permission is hereby granted, free of charge, to any person obtaining a copy  
  105.        of this software and associated documentation files (the "Software"), to deal  
  106.        in the Software without restriction, including without limitation the rights  
  107.        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
  108.        copies of the Software, and to permit persons to whom the Software is  
  109.        furnished to do so, subject to the following conditions:  
  110.        
  111.        The above copyright notice and this permission notice shall be included in all  
  112.        copies or substantial portions of the Software.  
  113.        
  114.        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
  115.        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
  116.        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
  117.        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
  118.        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
  119.        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  
  120.        SOFTWARE.   
  121.  
  122.  *)
  123.  
  124.  
  125. -- Gets invoked here when you run in AppleScript editor or double click on the app icon.
  126. on run
  127.     global debug
  128.     global squashRedundentURL
  129.     global droppedFileName
  130.    
  131.    
  132.     -- 3 and 6 are good to use
  133.     set debug to 0
  134.     -- 0 no debugging
  135.     -- 1 displays input and output to this routine & names of dropped files
  136.     -- 2 moderate
  137.     -- 3 display I'm here for important "on" blocks
  138.     -- 4 display  important data in important "on" blocks
  139.     -- 5  display I'm here for minor "on" blocks
  140.     -- 6 intense
  141.     -- 7 spewing routine "on" blocks   
  142.     -- 8 routines the spew lots of data
  143.    
  144.     -- Write a message into the event log.
  145.     log "  --- Starting on " & ((current date) as string) & " with level " & debug & " debug." & " --- "
  146.    
  147.     -- how do we process the <a> tag?
  148.     set squashRedundentURL to true
  149.     -- true -- get title for anchor
  150.     -- false -- let title of anchor be the same as the link
  151.    
  152.     -- debugging
  153.     set droppedFileName to "::: from clipboard :::"
  154.    
  155.     set lf to character id 10
  156.    
  157.     if debug ≥ 3 then log "in --- run ---"
  158.     -- initialize clipboard for debugging run
  159.     --set the clipboard to wrapupClipboardDataSelector()
  160.    
  161.     set theList to clipboard info
  162.     if debug ≥ 2 then printClipboardInfo(theList)
  163.    
  164.    
  165.    
  166.     set cbInfo to get (clipboard info) as string
  167.    
  168.     -- Most likely, if we have HTML data in the clipboard it will be from a web browser or Word.
  169.     if cbInfo contains "HTML" then
  170.        
  171.         if debug ≥ 2 then log "run: Working with HTML Class data from clipboard."
  172.         set theBoard to the clipboard as «class HTML»
  173.        
  174.         set normalHtml to do shell script "osascript -e 'try' -e 'get the clipboard as «class HTML»' -e 'end try' | awk '{sub(/«data HTML/, \"\") sub(/»/, \"\")} {print}' | xxd -r -p "
  175.         if debug ≥ 1 then
  176.             log "run: ...Print out plain text version of inputed HTML data from the clipboard..." & return & normalHtml
  177.             hexDumpFormatOne("run: after converting to printable, normalHtml", normalHtml)
  178.         end if
  179.        
  180.         set normalHtml to adjustCharacters(normalHtml)
  181.        
  182.         set returnedData to adjustBrowserHTML(normalHtml)
  183.         if debug ≥ 2 then
  184.             log "run: ...Print out plain text version of adjusted HTML data ..." & return & returnedData
  185.             log "run: ...just printed plain text version"
  186.             log "run: printed in hex"
  187.             hexDumpFormatOne("run: returnedData", returnedData)
  188.         end if
  189.        
  190.         set returnedData to convertToHTML(returnedData)
  191.         try
  192.             if debug ≥ 2 then log "returnedData is " & returnedData
  193.         on error errStr number errorNumber
  194.             log "run: ===> We didn't find HTML data.   errStr is " & errStr & " errorNumber is " & errorNumber
  195.             return 1
  196.         end try
  197.     else
  198.         -- will work with a plain html or plain text.
  199.         try
  200.             if debug ≥ 2 then log "Working with plain html or plain text"
  201.             set clipboardData to (the clipboard as text)
  202.             if debug ≥ 2 then
  203.                 log "run: class clipboardData is " & class of clipboardData
  204.                 log "run: continuing plain html or plain text"
  205.             end if
  206.            
  207.             if debug ≥ 1 then
  208.                 log "run: inputted clipboardData is " & clipboardData
  209.                 hexDumpFormatOne("run: inputted clipboardData", clipboardData)
  210.             end if
  211.         on error errStr number errorNumber
  212.             log "run: ===> We didn't find data on the clipboard.   errStr is " & errStr & " errorNumber is " & errorNumber
  213.             display dialog "We didn't find HTML source code nor plain text on the clipboard." & return & "Please copy from a different source." giving up after 15
  214.             return 1
  215.         end try
  216.         if debug ≥ 2 then log "run: calling common"
  217.         set returnedData to common(clipboardData)
  218.     end if
  219.     if debug ≥ 2 then log "run: place on the clipboard returnedData is " & returnedData
  220.     postToCLipboard(returnedData)
  221.     -- return code
  222.     return 0
  223.    
  224. end run
  225.  
  226. -- ------------------------------------------------------
  227. -- Folder actions.
  228. -- Gets invoked here when something is dropped on the folder that this script is monitoring.
  229. -- Right click on the folder to be monitored. services > Folder Action Settup...
  230. on adding folder items to this_folder after receiving added_items
  231.     -- Write a message into the event log.
  232.     log "  --- Starting on " & ((current date) as string) & " --- "
  233.     display dialog "TBD, some assembly required."
  234. end adding folder items to
  235.  
  236. -- ------------------------------------------------------
  237. (*
  238.  Gets invoked here when something is dropped on this AppleScript icon
  239. there seemed to be some confustion when calling the open handler directly from within run, so openContinued was created.
  240. *)
  241. on open dropped_items
  242.     global debug
  243.     global squashRedundentURL
  244.     global droppedFileName
  245.    
  246.     -- see on run for details
  247.     set debug to 1
  248.    
  249.     -- how do we process the <a> tag?
  250.     set squashRedundentURL to true
  251.     -- true -- get title for anchor
  252.     -- false -- let title of anchor be the same as the link
  253.    
  254.     -- for debugging error message
  255.     set droppedFileName to ""
  256.    
  257.     -- debuging for openContinued.  Displays timed display dialogs.
  258.     set localDebug to false
  259.     -- true displayed timed dialogs
  260.     -- false skip debuging
  261.    
  262.     set debugSeparator to true
  263.     -- true place a separator between the output of dropped files
  264.     -- false nothing is added      
  265.    
  266.     -- Write a message into the event log.
  267.     log "  --- Starting on " & ((current date) as string) & " --- "
  268.    
  269.     if debug ≥ 3 then log "in --- open ---"
  270.    
  271.     openContinued(dropped_items, localDebug, debugSeparator)
  272.    
  273.     -- we tried
  274.     return 0
  275.    
  276. end open
  277.  
  278. -- ------------------------------------------------------
  279. (*
  280. there seemed to be some confustion when calling the open handler directly from within run.
  281. *)
  282. on openContinued(droppedItems, localDebug, debugSeparator)
  283.     global debug
  284.     global squashRedundentURL
  285.     global droppedFileName
  286.    
  287.     if debug ≥ 3 then log "in --- openContinued ---"
  288.    
  289.     (*
  290.     -- Debug code. let's us select all items in a folder.
  291.       set fileName to choose file with prompt "get file"
  292.       set droppeditems to {fileName}
  293.     *)
  294.     if debug ≥ 2 then log "class of droppeditems is " & class of droppedItems
  295.     if (count of droppedItems) is 1 then
  296.         set substitueString to (count of droppedItems) & " item."
  297.     else
  298.         set substitueString to (count of droppedItems) & " items."
  299.     end if
  300.     display dialog "You dropped " & substitueString & return & "  Caveat emptor. You have been warned." giving up after 6
  301.    
  302.     set totalFileData to ""
  303.     repeat with droppedItem in droppedItems
  304.         set droppedFileName to droppedItem as string
  305.         if debug ≥ 1 then
  306.             log return & "... The droppedItem is " & (droppedItem as string) & " ... " & return
  307.             if localDebug then display dialog "processing file " & (droppedItem as string) giving up after 3
  308.             log "class = " & class of droppedItem
  309.         end if
  310.        
  311.         set extIs to findExtension(droppedItem)
  312.         set extIsU to makeCaseUpper(extIs)
  313.         if extIsU is "HTML" or extIsU is "HTM" or extIsU is "TEXT" or extIsU is "TXT" then
  314.             try
  315.                
  316.                 set theFileString to droppedItem as string
  317.                 if localDebug is true and debug is 0 then display dialog "theFileString " & return & theFileString giving up after 3
  318.                 set theFile to open for access file theFileString
  319.                 set allOfFile to read theFile
  320.                 close access theFile
  321.             on error theErrorMessage number theErrorNumber
  322.                 log "==> " & theErrorMessage & "error number " & theErrorNumber
  323.                 close access theFile
  324.             end try
  325.             if debug ≥ 2 then printHeader("read from file ( allOfFile )", allOfFile)
  326.            
  327.             --if localDebug then display dialog "processing " giving up after 3
  328.             if debugSeparator then
  329.                 -- get just the filename and extension
  330.                 set justTheName to last item of textToList(theFileString, ":")
  331.                 -- prevent your web broswer from acting on html like text
  332.                 set justTheName to alterString(justTheName, "&", "&amp;")
  333.                 set justTheName to alterString(justTheName, "<", "&lt;")
  334.                 set totalFileData to totalFileData & convertToHTML("<p><pre>&nbsp;&nbsp;--&gt;&nbsp;" & justTheName & "&nbsp&lt;--</pre></p>")
  335.                 if localDebug then display dialog "length and data of totalFileData   " & (length of totalFileData) & return & totalFileData giving up after 3
  336.             end if
  337.            
  338.             -- returns data converted to clipboard html
  339.             set totalFileData to totalFileData & common(allOfFile)
  340.             if localDebug then display dialog "after length and data of totalFileData   " & (length of totalFileData) & return & totalFileData giving up after 3
  341.         else
  342.             -- we do not support this extension
  343.             if localDebug then display dialog "We only support files with extenstion of html, htm, text or txt in either case. Your file had a " & extIs & " extention. Skipping" giving up after 10
  344.         end if
  345.     end repeat
  346.    
  347.     postToCLipboard(totalFileData)
  348.     if localDebug then display dialog "posted to clipboard length and data " & (length of totalFileData) & return & totalFileData giving up after 20
  349.     -- return code
  350.     return 0
  351. end openContinued
  352.  
  353. -- ------------------------------------------------------
  354. on common(clipboardData)
  355.     global debug
  356.     if debug ≥ 3 then log "in --- common ---"
  357.     set ht to character id 9
  358.     set lf to character id 10
  359.     set cbInfo to get (clipboard info) as string
  360.    
  361.     set clipboardData to adjustCharacters(clipboardData)
  362.     (*
  363.     -- for some crazy reason, I found hex "090a" (HT LF) in a html file.
  364.     set clipboardData to alterString(clipboardData, ht & lf, lf)
  365.     -- don't let Windoze confuse us. convert Return LineFeed to lf
  366.     set clipboardData to alterString(clipboardData, return & lf, lf)
  367.     -- might as will convert classic macOS return to lf. We will have to look for less things.
  368.     set clipboardData to alterString(clipboardData, return, lf)
  369.     if debug ≥ 2 then hexDumpFormatOne("change various line ends to a LF. clipboardData", clipboardData)
  370.     *)
  371.    
  372.     -- figure out what type of data we have: plain text or html source code text.
  373.     set paraCount to count of textToList(clipboardData, "<p")
  374.     set endparaCount to count of textToList(clipboardData, "</p>")
  375.     set titleCount to count of textToList(clipboardData, "<title")
  376.     set endTitleCount to count of textToList(clipboardData, "</title>")
  377.     set aLinkCount to count of textToList(clipboardData, "href=\"http")
  378.     -- mangled href="http
  379.     set mangledLinkCount to count of textToList(clipboardData, "href=\\\"http")
  380.     set brCount to count of textToList(clipboardData, "<br>")
  381.     if debug ≥ 2 then
  382.         log "common: Values used to distinguish HTML source code from plain text."
  383.         log "common: paraCount  is " & paraCount
  384.         log "common: endparaCount is " & endparaCount
  385.         log "common: titleCount is " & titleCount
  386.         log "common: endTitleCount is " & endTitleCount
  387.         log "common: aLinkCount is " & aLinkCount
  388.         log "common: brCount is " & brCount
  389.         log "common: mangledLinkCount is " & mangledLinkCount
  390.     end if
  391.    
  392.     -- note, textToList returns a count one greater than the actual because item one is the data before the first found entry.
  393.     if paraCount ≥ 4 and endparaCount ≥ 3 or brCount ≥ 4 or ((titleCount is endTitleCount) and titleCount ≥ 2) or aLinkCount ≥ 3 or mangledLinkCount ≥ 3 then
  394.         -- ASC tends to convert line-ends to either <p></p> or <p><br></p>. Isn't desireable for HTML input
  395.         if debug ≥ 2 then log return & "common:  ... found HTML input ... (in plain text format )." & return
  396.         set clipboardData to adjustBrowserHTML(clipboardData)
  397.        
  398.     else
  399.         if debug ≥ 2 then log "common: ... found plain Text input ..."
  400.         set clipboardData to typeText(clipboardData)
  401.     end if
  402.     set readyData to convertToHTML(clipboardData)
  403.     if debug ≥ 4 then log "bye, bye from  -.- common -.-"
  404.     return readyData
  405. end common
  406.  
  407. -- ------------------------------------------------------  
  408. (* add paragraphs *)
  409. on addParagraphs(theOutputBuffer)
  410.     global debug
  411.     if debug ≥ 3 then log "in --- addParagraphs ---"
  412.     set lf to character id 10
  413.    
  414.     -- start the theOutputBuffer with a paragraph tag.  We are taking a simple approach at this time.
  415.     set theOutputBuffer to "<p>" & theOutputBuffer
  416.     --  LF
  417.     -- Remember CRLF was changed to LF above and CR was chanaged to LF above.
  418.     -- we don't want no Windoze problems
  419.     set theOutputBuffer to alterString(theOutputBuffer, lf & lf, "</p><p> </p><p>")
  420.    
  421.     -- Does the string end with a dangling paragraph?  
  422.     if debug ≥ 5 then
  423.         log "length of theOutputBuffer is " & length of theOutputBuffer
  424.     end if
  425.     if (length of theOutputBuffer) > (length of "</p>") then
  426.         if text ((length of theOutputBuffer) - 2) thru (length of theOutputBuffer) of theOutputBuffer is "<p>" then
  427.             set theOutputBuffer to text 1 thru ((length of theOutputBuffer) - 3) of theOutputBuffer
  428.         else if text ((length of theOutputBuffer) - 2) thru (length of theOutputBuffer) of theOutputBuffer is not "</p>" then
  429.             set theOutputBuffer to theOutputBuffer & "</p>"
  430.         end if
  431.     end if
  432.     if debug ≥ 4 then log "bye from  -.- addParagraphs -.-"
  433.     return theOutputBuffer
  434. end addParagraphs
  435.  
  436. -- ------------------------------------------------------
  437. (*
  438.   We received HTML class data on the clipboard.  This is the manager.
  439.   At this point, we expect only LFs in the text.
  440.  *)
  441. on adjustBrowserHTML(normalHtml)
  442.     global debug
  443.     if debug ≥ 3 then log "in --- adjustBrowserHTML ---"
  444.     set lf to character id 10
  445.    
  446.     set alteredHTML to adjustURLs(normalHtml, {"https://", "http://", "<a ", "<img"})
  447.     set alteredHTML to adjustToAscHTML(alteredHTML)
  448.     if debug ≥ 4 then log "bye from  -.- adjustBrowserHTML -.-"
  449.     return alteredHTML
  450. end adjustBrowserHTML
  451.  
  452. -- ------------------------------------------------------
  453. (*
  454.     Symbol  Meaning                 Hex     Used
  455.         CR      Carriage Return         0d      classic Macintosh
  456.         LF      Line Feed                       0a      UNIX
  457.         CR/LF   Carriage Return/Line Feed   0d0a    MS-DOS, Windows, OS/2
  458.        
  459.     8230    U+2026  E2 80 A6    … Horizontal Ellipsis
  460.         https://www.charset.org/utf-8/9
  461.        &hellip;
  462.         https://www.toptal.com/designers/htmlarrows/punctuation/horizontal-ellipsis/
  463.  
  464.     *)
  465. on adjustCharacters(normalHtml)
  466.     global debug
  467.     set ht to character id 9 -- horizontal tab
  468.     set lf to character id 10
  469.     set ellipsis1 to character id 226
  470.     set ellipsis2 to character id 128
  471.     set ellipsis3 to character id 166
  472.    
  473.     if debug ≥ 3 then log "in --- adjustCharacters() ---"
  474.    
  475.     -- for some reason web broswers are having difficulty with utf-8 E2 80 A6
  476.     -- so convert to a HTML entity.  does work in <pre>
  477.     set normalHtml to alterString(normalHtml, ellipsis1 & ellipsis2 & ellipsis3, "&hellip;")
  478.    
  479.     -- don't let Windoze confuse us. convert Return LineFeed to lf
  480.     set normalHtml to alterString(normalHtml, return & lf, lf)
  481.     -- might as will convert classic macOS return to lf. We will have to look for less things.
  482.     set normalHtml to alterString(normalHtml, return, lf)
  483.     if debug ≥ 3 then hexDumpFormatOne("adjustCharacters: after altering characters normalHtml", normalHtml)
  484.     return normalHtml
  485. end adjustCharacters
  486.  
  487. -- ------------------------------------------------------
  488. (*
  489.    Is the displayed title the same as the href URL?
  490.    <a href="https://support.apple.com/en-ca/HT204759">https://support.apple.com/en-ca/HT204759</a>
  491.  
  492.    -- span tag; blank before https:  
  493.   <a href="https://reportaproblem.apple.com/?s=6"><span style="font-family: Arial;"> https://reportaproblem.apple.com/?s=6</span></a>
  494.  
  495.   -- blank display field
  496.   <a href="https://reportaproblem.apple.com/?s=6"></a>
  497.  
  498.   -- guard against http in DOCTYPE.
  499.   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  500.   https://html.com/tags/doctype/
  501.  
  502. *)
  503. on adjustDuplicateAnchorURLs(anchorTagInput)
  504.     global debug
  505.     global squashRedundentURL
  506.     set lf to character id 10
  507.    
  508.     if debug ≥ 3 then log "in --- adjustDuplicateAnchorURLs ---"
  509.    
  510.     -- reduce LFs in title
  511.     set anchorTagString to alterString(anchorTagInput, lf, " ")
  512.     if debug ≥ 2 then hexDumpFormatOne("  adjustDuplicateAnchorURLs: anchorTagString", anchorTagString)
  513.    
  514.     -- Does the user want us to get the title for duplicate URLs?
  515.     if squashRedundentURL is false then
  516.         return anchorTagString -- --------- ignore duplicates ---------->
  517.     end if
  518.    
  519.     set splitList to textToList(anchorTagString, "href=")
  520.     if debug ≥ 4 then printList("adjustDuplicateAnchorURLs: splitList", splitList)
  521.     -- Deal with document anchor points.  <a href="#refunds">Refunds</a>
  522.     if (count of splitList)1 then
  523.         -- we didn't find a linking anchor point. no href.
  524.         return anchorTagString -- --------- not a linking <a> tag  ---------->
  525.     end if
  526.    
  527.     -- get href url.
  528.     set hrefURL to tagContent(item 2 of splitList, "\"", "\"")
  529.     if debug ≥ 2 then log "  adjustDuplicateAnchorURLs: hrefURL is " & hrefURL
  530.    
  531.     -- get display information
  532.     set titleURL to tagContent(item 2 of splitList, ">", "</a>")
  533.     if debug ≥ 2 then log "  adjustDuplicateAnchorURLs: titleURL is " & titleURL
  534.    
  535.     -- for the display text to contain an URL it must be at least "http://" characters long.
  536.     if (length of titleURL)(length of "http://") then
  537.         -- we didn't find a url in the display text
  538.         return anchorTagString -- --------- no url in display text  ---------->
  539.     end if
  540.    
  541.    
  542.     -- http or https?
  543.     set aTagSeparator to ""
  544.     -- note, in case the delimiter isn't found all the text is returen in item # 1
  545.     set splitURLhttp to splitTextToList(titleURL, "http://")
  546.     if debug ≥ 2 then log "count of splitURLhttp is " & (count of splitURLhttp)
  547.     if debug ≥ 2 then printList("adjustDuplicateAnchorURLs: splitURLhttp is", splitURLhttp)
  548.    
  549.     set splitURLhttps to splitTextToList(titleURL, "https://")
  550.     if debug ≥ 2 then log "adjustDuplicateAnchorURLs: count of splitURLhttps is " & (count of splitURLhttps)
  551.     if debug ≥ 2 then printList("adjustDuplicateAnchorURLs: splitURLhttps is", splitURLhttps)
  552.    
  553.     set splitURLhttpLength to length of (item 1 of splitURLhttp)
  554.     set LengthsplitURLhttps to length of (item 1 of splitURLhttps)
  555.    
  556.     -- did we find the http:// header?
  557.     if (count of splitURLhttp)2 then
  558.         if debug ≥ 2 then log "adjustDuplicateAnchorURLs: http found"
  559.         set aTagSeparator to (item 1 of splitURLhttp)
  560.         -- might be a little too general.  allows blanks and line ends in the middle of the url
  561.         -- when I have seen them only in front and end.
  562.         set {titleURL, trailingText} to urlEndsWHere(item 2 of splitURLhttp)
  563.        
  564.         -- did we find the https:// header? Hence, item # 2 will be present containing what's after
  565.         -- https://
  566.     else if (count of splitURLhttps)2 then
  567.         if debug ≥ 2 then log "adjustDuplicateAnchorURLs: https found"
  568.         set aTagSeparator to (item 1 of splitURLhttps)
  569.         -- ditto
  570.         set {titleURL, trailingText} to urlEndsWHere(item 2 of splitURLhttps)
  571.     else
  572.         if debug ≥ 2 then log "adjustDuplicateAnchorURLs: no url in display text"
  573.         -- RW puts a blank character in front of the display string :-(
  574.         if length of titleURL > 0 then
  575.             if debug ≥ 2 then log "adjustDuplicateAnchorURLs: commentry title text"
  576.             return anchorTagString -- --------- ignore duplicates ---------->          
  577.         end if
  578.         ---------------------------------------- need to adjust above ..............
  579.         -- text in display text, so insert title from hrefURL.  
  580.         -- some web browsers use hrefURL
  581.         set titleURL to hrefURL
  582.     end if
  583.     if debug ≥ 2 then log "adjustDuplicateAnchorURLs: length of aTagSeparator is " & (length of aTagSeparator) & "aTagSeparator is ->" & aTagSeparator & "<-"
  584.     -- make the comparison
  585.     if debug ≥ 2 then log "  ajdustDuplicateAnchorURLs: hrefURL is " & return & hrefURL & return & " titleURL is " & return & titleURL
  586.     if hrefURL is not titleURL then
  587.         if debug ≥ 2 then "adustDuplicateAnchorURLs: href and display text are different."
  588.         return anchorTagString -- --------- assume we have the title ---------->
  589.     end if
  590.    
  591.     -- They are the same
  592.     if debug ≥ 2 then log "  adjustDuplicateAnchorURLs: href and title are the same."
  593.     set gotTitle to getTitle(hrefURL)
  594.     if debug ≥ 2 then log "  adustDuplicateAnchorURLs: gotTitle is " & gotTitle
  595.    
  596.     -- build anchor tag.
  597.     set anchorTrailer to textToList(item 2 of splitList, ">")
  598.     if debug ≥ 4 then printList("adjustDuplicateAnchorURLs: anchorTrailer", anchorTrailer)
  599.     set anchorTagOutput to (item 1 of splitList) & " href=" & item 1 of anchorTrailer & ">" & aTagSeparator & gotTitle & trailingText & "</a>"
  600.     if debug ≥ 2 then log "  adjustDuplicateAnchorURLs: anchorTagOutout is " & anchorTagOutput
  601.     return anchorTagOutput
  602.    
  603.    
  604. end adjustDuplicateAnchorURLs
  605.  
  606. -- ------------------------------------------------------
  607. -- called for HTML processing
  608. on adjustLF(theBuffer)
  609.     global debug
  610.     set ht to character id 9
  611.     set lf to character id 10
  612.     if debug ≥ 3 then log "in --- adjustLF() ---"
  613.     if debug ≥ 2 then hexDumpFormatOne("  adjustLF: input from theBuffer", theBuffer)
  614.     set numberOfLf to 1 -- for debuggin so we can display loop count
  615.    
  616.     set inputLfBuffer to theBuffer -- now, input data
  617.     set outputBuildLf to "" -- output data
  618.     -- copy & change
  619.     -- ditch leading LFs
  620.     repeat while length of inputLfBuffer ≥ 2 and text 1 thru 1 of inputLfBuffer is lf
  621.         if debug ≥ 2 then log "  adjustLF: found leading lf. current length of inputLfBuffer is " & getIntegerAndHex(length of inputLfBuffer)
  622.         -- just lob off LF
  623.         set inputLfBuffer to text 2 thru -1 of inputLfBuffer
  624.        
  625.         if debug ≥ 2 then log "  adjustLF: next text character is ->" & (text 1 thru 1 of inputLfBuffer) & "<-"
  626.     end repeat
  627.     -- for some crazy reason, I found hex "090a" (HT LF) in a html file.
  628.     set inputLfBuffer to alterString(inputLfBuffer, ht & lf, lf)
  629.     repeat until inputLfBuffer is ""
  630.        
  631.         set whereLfOffset to offset of lf in inputLfBuffer
  632.         if debug ≥ 2 then log "  adjustLF: whereLfOffset is " & whereLfOffset & " in hex " & integerToHex(whereLfOffset)
  633.        
  634.         -- get before and after characters if present.
  635.         if whereLfOffset ≥ 2 then
  636.             set priorCharacter to (text (whereLfOffset - 1) thru (whereLfOffset - 1) in inputLfBuffer)
  637.         else
  638.             set priorCharacter to ""
  639.         end if
  640.         if whereLfOffset ≥ (length of inputLfBuffer) then
  641.             -- no following character
  642.             set followingCharacter to ""
  643.         else
  644.             set followingCharacter to (text (whereLfOffset + 1) thru (whereLfOffset + 1) in inputLfBuffer)
  645.         end if
  646.         if debug ≥ 2 then log "  adjustLF: priorCharacter is >" & priorCharacter & "< followingCharacter is >" & followingCharacter & "<"
  647.        
  648.         -- process the LF. 
  649.         if (whereLfOffset is 1) and ((length of inputLfBuffer)2) then
  650.             set inputLfBuffer to text 2 thru -1 of inputLfBuffer
  651.             if debug ≥ 2 then log "  adjustLF: leading lf.  Got rid of it."
  652.             -- nothing to move to outputBuildLf            
  653.         else if (whereLfOffset is 1) and ((length of inputLfBuffer) is 1) then
  654.             -- we have found all theLFs to find.
  655.             set inputLfBuffer to ""
  656.             if debug ≥ 2 then log "  adjustLF: only one character left.  Got rid of it."
  657.         else if followingCharacter is "" then
  658.             if debug ≥ 2 then log "null"
  659.             -- didn't we just check this? Yes, but we need to iterate somehow.
  660.             set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, " ")
  661.             -- just skip it, so we don't have to put anything on outputBuildLf
  662.         else if priorCharacter is not ">" and priorCharacter is not " " and followingCharacter is lf then
  663.             -- reduce a series of LFs to one blank
  664.             -- the next time around the next LF will be comparing to the prior character
  665.             -- as a blank
  666.             if debug ≥ 2 then log "  adjustLF: series of LFs"
  667.             set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, " ")
  668.         else if priorCharacter is " " and followingCharacter is tab then
  669.             -- reduce a series of LFs to one blank
  670.             -- the next time around the next LF will be comparing to the prior character
  671.             -- as a blank
  672.             if debug ≥ 2 then log "  adjustLF: series of LFs"
  673.             set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, "")
  674.             set {inputLfBuffer, outputBuildLf} to trimCharacters(inputLfBuffer, outputBuildLf, tab)
  675.         else if priorCharacter is ">" and followingCharacter is not " " then
  676.             --  LF after HTML tag. no real need for lf here.  asc tends to make these into <p></p>
  677.             if debug ≥ 2 then log "  adjustLF: found a tag"
  678.             -- copy prior stuff
  679.             set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, "")
  680.         else if followingCharacter is lf then
  681.             -- prevent double LFs.
  682.             if debug ≥ 2 then log "  adjustLF: prevent double LFs at" & getIntegerAndHex(whereLfOffset)
  683.             set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, "")
  684.             -- middle of text
  685.         else if (whereLfOffset < (length of inputLfBuffer)) and followingCharacter is " " then
  686.             -- we need to avoid double blanks
  687.             -- purge
  688.             if debug ≥ 2 then log "  adjustLF: getting rid of lf at " & getIntegerAndHex(whereLfOffset)
  689.             -- skip lf.
  690.             set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, " ")
  691.             -- get read of leading spaces.  That is the spaces after the lf
  692.             set {inputLfBuffer, outputBuildLf} to trimCharacters(inputLfBuffer, outputBuildLf, " ")
  693.         else
  694.             -- assume there are character before and after the LF.
  695.             if debug ≥ 2 then log "  adjustLF: punt."
  696.             -- replace with blank
  697.             set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, " ")
  698.         end if
  699.        
  700.         if debug ≥ 2 then
  701.             hexDumpFormatOne("  adjustLF: outputBuildLf of " & numberOfLf, outputBuildLf)
  702.             hexDumpFormatOne("  adjustLF: inputLfBuffer of " & numberOfLf, inputLfBuffer)
  703.         end if
  704.         -- next pass will be
  705.         set numberOfLf to numberOfLf + 1
  706.     end repeat
  707.     if debug ≥ 4 then log "bye from  -.- adjustLF() -.-"
  708.     return outputBuildLf
  709. end adjustLF
  710.  
  711. -- ------------------------------------------------------
  712. (* ASC likes to insert lots of white space into a page.
  713.   This routine attempt to fix up the html to avoid
  714.   all the extra white-space.
  715.  
  716.    Minimize the amount of white space inserted.
  717.  *)
  718.  
  719. on adjustToAscHTML(ascHtml)
  720.     global debug
  721.     if debug ≥ 3 then log "in --- adjustToAscHtml ---"
  722.     set lf to character id 10
  723.     set numberOfPres to 1
  724.     -- In the context of HTML, LF should mostly be insignificant.
  725.     -- Would be bad to change a LF inside the <pre>  tag.
  726.     --skip changing lf in "<pre>.  
  727.     set buildHtml to "" -- will contain the output
  728.     if debug ≥ 2 then log "adjustToAscHTML: find <pre>s"
  729.     -- copy & change
  730.     if (offset of "</pre>" in ascHtml) is not 0 then
  731.         repeat while (offset of "</pre>" in ascHtml) is not 0
  732.             -- get text before "<pre" tag
  733.             set splitString to item 1 of splitTextToList(ascHtml, "<pre")
  734.             if debug ≥ 2 then
  735.                 log "adjustToAscHTML: splitString is " & splitString
  736.                 hexDumpFormatOne("adjustToAscHTML: buildHtml *before* adjustLF()", buildHtml)
  737.             end if
  738.             set buildHtml to buildHtml & adjustLF(splitString)
  739.             if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: buildHtml after adjustLF()", buildHtml)
  740.            
  741.             -- lob off header text we processed
  742.             -- while we found the text before "<pre", we still need to get it out
  743.             -- of ascHtml
  744.             --  & gets rid of the token ("<pre"), so fix
  745.             set ascHtml to "<pre" & chompLeftAndTag(ascHtml, "<pre")
  746.            
  747.             -- any more <pre> tags?
  748.             if ascHtml is "" then
  749.                 display dialog "adjustToAscHTML: HTML missing </pre> tag. possible logic error." giving up after 10
  750.                 -- none. We have already adjusted buildHtml
  751.                 exit repeat -- ------ done processing ascHtml ------>
  752.             end if
  753.             if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: remaining ascHtml is ", ascHtml)
  754.            
  755.             -- tack on the unaltered <pre>..</pre> stuff
  756.             set buildHtml to buildHtml & (item 1 of splitTextToList(ascHtml, "</pre>")) & "</pre>"
  757.             if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: buildHtml after finding </pre>", buildHtml)
  758.            
  759.             set ascHtml to chompLeftAndTag(ascHtml, "</pre>")
  760.             if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: ascHtml end of " & numberOfPres & " pass", ascHtml)
  761.             set numberOfPres to numberOfPres + 1
  762.            
  763.         end repeat
  764.         -- remainder
  765.         set buildHtml to buildHtml & adjustLF(ascHtml)
  766.         set ascHtml to ""
  767.     else
  768.         -- lf's are only signigicant in <pre>...</pre>
  769.         if debug ≥ 2 then log "adjustToAscHTML: didn't find a <pre>"
  770.         -- all others are white space.
  771.         set buildHtml to adjustLF(ascHtml)
  772.         set ascHtml to "" -- input text processed
  773.     end if
  774.    
  775.    
  776.     (*
  777.     Hack about to fix ASC interpretation of HTML.
  778.    
  779.     ASC alters the definition of a paragraph to have not space before or after the paragraph.
  780.     A paragraph like <p></p> works like a <br>.
  781.    
  782.     Consequently, ASC converts <p> </p> to <p><br></p>, that is a
  783.     space only paragraph to a paragraph with a <br> in it.
  784.    
  785.     the code converts one tag on a line to a line of tags.
  786.     </ol>
  787.     </p>
  788.     <p>
  789.     converted form
  790.     </ol></p><p>
  791.    
  792.     so that means a change on </ol></p><p> converts both the multi-lines form and the single line form.
  793.    
  794.     *)
  795.     set buildHtml to alterString(buildHtml, "<br> ", "<br>")
  796.     -------------------- failure???
  797.     --set buildHtml to alterString(buildHtml, "<p> ", "<p>")
  798.    
  799.     -- asc paragraphs don't generate space before and after the paragraph.
  800.     set buildHtml to alterString(buildHtml, "</p><p></p><p></p>", "</p><p> </p><p></p>")
  801.    
  802.     set buildHtml to alterString(buildHtml, "</p><p></p><p></p>", "</p><p> </p><p></p>")
  803.    
  804.     set buildHtml to alterString(buildHtml, "</ol></p><p>", "</ol><p> </p></p><p>")
  805.     (*
  806.     surprisingly ASC converts <p> </p> to <p><br></p>, that is a
  807.     space only paragraph to a paragraph with a <br> in it.
  808.    
  809.     the code converts one tag on a line to a line of tags.
  810.     </ol>
  811.     </p>
  812.     <p>
  813.     converted form
  814.     </ol></p><p>
  815.    
  816.     so that means a change on </ol></p><p> converts both the multi-lines form and the single line form.
  817.    
  818.     *)
  819.     --set buildHtml to alterString(buildHtml, "<p> </p>", "<p></p>")
  820.     if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: complete buildHtml ", buildHtml)
  821.     if debug ≥ 4 then log "bye from  -.- adjustToAscHTML -.-"
  822.     return buildHtml
  823. end adjustToAscHTML
  824.  
  825. -- ------------------------------------------------------
  826. (*
  827. example:
  828.   Free version of Parallels for individual use:</p><p><br></p>
  829.   <p>https://itunes.apple.com/us/app/parallels-desktop-lite/id1085114709?mt=12</p>
  830.   <p><br></p>
  831.   <p>Full version</p><p><a href="http://www.parallels.com/en/products/desktop/" target="_blank">
  832.      http://www.parallels.com/en/products/desktop/</a>
  833.      
  834. If asc find a URL outside of an a tag, it will place blank lines around the URL. No, it will not go the
  835. full nine yards and place an a tag around the url.
  836.  
  837. *)
  838. on adjustURLs(theOriginalInputBuffer, linkList)
  839.     -- linkList is what type of links are we searching for.
  840.     global debug
  841.     if debug ≥ 3 then log "in --- adjustURLs ---"
  842.     set alteredBuffer to false
  843.     set lf to character id 10
  844.     set theInputBuffer to theOriginalInputBuffer
  845.     if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: theInputBuffer", theInputBuffer)
  846.    
  847.     -- we end up in a lot of grief when the buffer ends without
  848.     -- a line-end
  849.     if text (length of theInputBuffer) thru (length of theInputBuffer) of theInputBuffer is not lf then
  850.         -- tack LF at the end
  851.         set alteredBuffer to true
  852.         set theInputBuffer to theInputBuffer & lf
  853.         if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: theInputBuffer", theInputBuffer)
  854.     end if
  855.    
  856.     set buildHtml to ""
  857.     -- DOCTYPE contains a http link, but it's not something we want to mess with.
  858.     set {buildHtml, theInputBuffer} to skipDoctype(buildHtml, theInputBuffer)
  859.    
  860.     set countI to 1 -- variable is used for debuging.
  861.     -- do until we have processed theInputBuffer
  862.     repeat until theInputBuffer is ""
  863.         if debug ≥ 2 then log "  adjustURLs: at the top of theInputBuffer ........."
  864.        
  865.         set foundWhere to {}
  866.         repeat with lookCharacters in linkList
  867.             copy (offset of lookCharacters in theInputBuffer) to the end of the foundWhere
  868.             try
  869.                 set tempLoc to (offset of lookCharacters in theInputBuffer)
  870.                 if debug ≥ 2 then log "  adjustURLs: searching for " & lookCharacters & " found at offset  " & tempLoc & " contains " & text tempLoc thru (tempLoc + ((length of lookCharacters) - 1)) of theInputBuffer
  871.             end try
  872.         end repeat
  873.         if debug ≥ 2 then log foundWhere
  874.         set foundMarkerOffset to (minimumPositiveNumber from foundWhere)
  875.         -- figure out what type of marker we got?
  876.        
  877.         -- None.  Reached the end of the data without finding one.
  878.         if foundMarkerOffset ≤ 0 then
  879.             -- we are done
  880.             if debug ≥ 2 then log "  adjustURLs: Found all links."
  881.             set buildHtml to buildHtml & theInputBuffer
  882.             if debug ≥ 2 then printHeader("  adjustURLs: buildHTML", buildHtml)
  883.             set theInputBuffer to ""
  884.             exit repeat -- ------ done processing theInputBuffer ------>
  885.         end if
  886.        
  887.         -- find which marker did we found.
  888.         -- seems a bit redunant.
  889.         set actualMarker to ""
  890.         if (text foundMarkerOffset thru (foundMarkerOffset + 2) of theInputBuffer) is "<a " then
  891.             set actualMarker to "<a "
  892.         else if text foundMarkerOffset thru (foundMarkerOffset + 3) of theInputBuffer is "<img" then
  893.             set actualMarker to "<img"
  894.         else if text foundMarkerOffset thru (foundMarkerOffset + 6) of theInputBuffer is "http://" then
  895.             set actualMarker to "http://"
  896.         else if text foundMarkerOffset thru (foundMarkerOffset + 7) of theInputBuffer is "https://" then
  897.             set actualMarker to "http://"
  898.         else
  899.             display dialog "Missed marker tag  Found " & text foundMarkerOffset thru (foundMarkerOffset + 7) of theInputBuffer & " We will continue on, but no one knows how well." giving up after 10
  900.             log "  adjustURLs: ==> Missed marker tag.  Found " & text foundMarkerOffset thru (foundMarkerOffset + 7) of theInputBuffer
  901.             return theOriginalInputBuffer
  902.         end if
  903.         set actualMarkerOffsetLength to ((length of actualMarker) - 1)
  904.         if debug ≥ 2 then
  905.             log "  adjustURLs: actualMarker is " & actualMarker & " actualMarkerOffsetLength is " & actualMarkerOffsetLength
  906.             log "  adjustURLs: foundMarkerOffset is " & getIntegerAndHex(foundMarkerOffset) & "  verify marker text is " & text foundMarkerOffset thru (foundMarkerOffset + actualMarkerOffsetLength) of theInputBuffer
  907.         end if
  908.        
  909.        
  910.         if foundMarkerOffset ≥ 2 then
  911.             -- collect and strip off characters that are before the marker.
  912.             if debug ≥ 2 then
  913.                 log "  adjustURLs: buildHTML is " & buildHtml & " length is " & getIntegerAndHex(length of buildHtml)
  914.                 hexDumpFormatOne("  adjustURLs: theInputBuffer", theInputBuffer)
  915.                 log "  adjustURLs:  (foundMarkerOffset - 1) is " & getIntegerAndHex((foundMarkerOffset - 1))
  916.             end if
  917.             -- get the proceding text
  918.             set buildHtml to buildHtml & text 1 thru (foundMarkerOffset - 1) of theInputBuffer
  919.             if debug ≥ 2 then
  920.                 log "  adjustURLs: buildHTML is " & buildHtml
  921.                 hexDumpFormatOne("  adjustURLs: buildHTML", buildHtml)
  922.             end if
  923.            
  924.             -- https://apple.stackexchange.com/a/20135/44531
  925.            
  926.             set theInputBuffer to text foundMarkerOffset thru -1 of theInputBuffer --trim off character before what we found
  927.             if debug ≥ 2 then
  928.                 printHeader("  adjustURLs: theInputBuffer", theInputBuffer)
  929.                 hexDumpFormatOne("  adjustURLs: theInputBuffer", theInputBuffer)
  930.             end if
  931.         else
  932.             log "  adjustURLs: ==> no proceeding data."
  933.         end if
  934.        
  935.         repeat 1 times -- interate loop
  936.            
  937.             -- example" the url is also the display text
  938.             -- <a href="https://discussions.apple.com/docs/DOC-8841" target="_blank">https://discussions.apple.com/docs/DOC-8841</a>
  939.             if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: theInputBuffer", theInputBuffer)
  940.            
  941.             -- check for the <a> tag
  942.             if text 1 thru (length of "<a ") of theInputBuffer is "<a " then
  943.                 -- found <a> tag
  944.                 if debug ≥ 2 then log "  adjustURLs: processing <a> tag"
  945.                 -- ASC consider a line-end as a <br> when when firefox considers it a blank
  946.                 -- change a possible line-end before an <a> tag to a " "
  947.                 if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: before lf check buildHTML", buildHtml)
  948.                 if text (length of buildHtml) thru (length of buildHtml) of buildHtml is lf then
  949.                     if debug ≥ 2 then log "  adjustURLs: we need to delete a line-end before the <a> tag"
  950.                     set buildHtml to text 1 thru ((length of buildHtml) - 1) of buildHtml
  951.                     set buildHtml to buildHtml & " "
  952.                     if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: after lf deletion buildHTML", buildHtml)
  953.                 end if
  954.                 -- find ending </a> tag
  955.                 set whereEnds to offset of "</a>" in theInputBuffer
  956.                 if whereEnds ≤ 0 then
  957.                     if debug ≥ 2 then log "  adjustURLs: ==> found an error in the HTML.  no ending </a>"
  958.                     set buildHtml to buildHtml & theInputBuffer
  959.                     printHeader("  adjustURLs: buildHTML", buildHtml)
  960.                     set theInputBuffer to ""
  961.                     display dialog "  adjustURLs: Found an error in the HTML.  No ending </a>.  Will skip." giving up after 10
  962.                     exit repeat -- ------ next ------>
  963.                 end if
  964.                 set lastOffsetLength to ((length of "</a>") - 1)
  965.                 if debug ≥ 2 then log "  adjustURLs: lastOffsetLength is " & lastOffsetLength
  966.                 set lastCharacterOffset to whereEnds + lastOffsetLength
  967.                 if debug ≥ 2 then log "  adjustURLs: lastCharacterOffset is " & getIntegerAndHex(lastCharacterOffset)
  968.                 -- needs to copy the ending ">"
  969.                 set anchorString to text 1 thru lastCharacterOffset of theInputBuffer
  970.                 -- don't let Windoze confuse us. convert Return LineFeed to lf
  971.                 -- Correct absure ASC bug where there is a line-end in the <a> text.
  972.                 if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: before adjusting anchorString", anchorString)
  973.                 set anchorString to alterString(anchorString, lf, " ")
  974.                 if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: anchorString", anchorString)
  975.                 set anchorString to adjustDuplicateAnchorURLs(anchorString, lf, " ")
  976.                 --
  977.                 -- fix up mangled url
  978.                 -- be a nice guy for RW -???-
  979.                 -- Waterfox fixes up!
  980.                 --  
  981.                 set buildHtml to buildHtml & anchorString
  982.                 if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: buildHTML", buildHtml)
  983.                 -- https://apple.stackexchange.com/a/20135/44531
  984.                 -- We want first character of the "next" portion of theInputBuffer so add one
  985.                 set theInputBuffer to text (lastCharacterOffset + 1) thru -1 of theInputBuffer --trim out <a>
  986.                 if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: theInputBuffer", theInputBuffer)
  987.                 -- Web Browsers like Firefox convert a line-end in text to a space.
  988.                 if text 1 thru 1 of theInputBuffer is lf then
  989.                     if (length of theInputBuffer) is 1 then
  990.                         set theInputBuffer to " "
  991.                     else
  992.                         set theInputBuffer to " " & (text 2 thru (length of theInputBuffer) of theInputBuffer)
  993.                         if debug ≥ 2 then hexDumpFormatOne("  adjustURLs: after lf deletion; theInputBuffer", theInputBuffer)
  994.                     end if
  995.                 end if
  996.                 exit repeat -- ------ next ------>
  997.             end if
  998.            
  999.             -- skip img tag which may contian a http or https.
  1000.             if text 1 thru (length of "<img") of theInputBuffer is "<img" then
  1001.                 -- found <img> tag
  1002.                 if debug ≥ 2 then log "  adjustURLs: processing <img> tag"
  1003.                 set {buildHtml, theInputBuffer} to skipTag(buildHtml, theInputBuffer, ">")
  1004.                 exit repeat -- ------ next ------>
  1005.             end if
  1006.            
  1007.             set {theURL, theInputBuffer} to urlEndsWHere(theInputBuffer)
  1008.            
  1009.             if debug ≥ 2 then printHeader("  adjustURLs: printHeader", theInputBuffer)
  1010.            
  1011.             set actualTagData to getTitle(theURL)
  1012.            
  1013.             -- fyi: The string " _blank" in the <a> oOpens the linked document in a new window or tab.
  1014.             set assembled to "<a href=\"" & theURL & "\" target=\"_blank\">" & actualTagData & "</a>"
  1015.             if debug ≥ 2 then log "  adjustURLs: assembled  is " & assembled
  1016.            
  1017.             if (length of theInputBuffer)0 then
  1018.                 -- We have reached the end of the input
  1019.                 if debug ≥ 2 then log "  adjustURLs: we have reached the end of the input."
  1020.                 set buildHtml to buildHtml & assembled
  1021.             else
  1022.                 if debug ≥ 2 then log "  adjustURLs: more input to process"
  1023.                 set buildHtml to buildHtml & assembled
  1024.             end if
  1025.            
  1026.             -- wrap up
  1027.             --log "transformed text from buildHTML is  " & return & buildHTML
  1028.             if debug ≥ 2 then log "  adjustURLs: #" & countI & " transformed text from buildHTML is  " & return & buildHtml
  1029.             -- number of links found
  1030.             set countI to countI + 1
  1031.            
  1032.         end repeat -- used to interate
  1033.     end repeat -- processing links in the input text
  1034.     if alteredBuffer is true then
  1035.         -- chop off the lf we added above.
  1036.         set buildHtml to text 1 thru ((length of buildHtml) - 1) of buildHtml
  1037.         set alteredBuffer to false -- somewhat redundant
  1038.     end if
  1039.     if debug ≥ 4 then log "bye from  -.- adjustURLs -.-"
  1040.     return the buildHtml
  1041.    
  1042. end adjustURLs
  1043.  
  1044. -- ------------------------------------------------------
  1045. (*
  1046. alterString
  1047.   thisText is the input string to change
  1048.   delim is what string to change.  It doesn't have to be a single character.
  1049.   replacement is the new string
  1050.  
  1051.   returns the changed string.
  1052. *)
  1053.  
  1054. on alterString(thisText, delim, replacement)
  1055.     global debug
  1056.     if debug ≥ 5 then log "in ~~~ alterString ~~~"
  1057.     set resultList to {}
  1058.     set {tid, my text item delimiters} to {my text item delimiters, delim}
  1059.     try
  1060.         set resultList to every text item of thisText
  1061.         set text item delimiters to replacement
  1062.         set resultString to resultList as string
  1063.         set my text item delimiters to tid
  1064.     on error
  1065.         set my text item delimiters to tid
  1066.     end try
  1067.     return resultString
  1068. end alterString
  1069.  
  1070. -- ------------------------------------------------------
  1071. (*
  1072.   Return the text to the right of theToken.
  1073. *)
  1074. on answerAndChomp(theString, theToken)
  1075.     global debug
  1076.     if debug ≥ 5 then log "in ~~~ answerAndChomp ~~~"
  1077.     set theOffset to offset of theToken in theString
  1078.     if debug ≥ 7 then log "theOffset is " & theOffset
  1079.     set theLength to length of theString
  1080.     if theOffset > 0 then
  1081.         set beginningPart to text 1 thru (theOffset - 1) of theString
  1082.         if debug ≥ 7 then log "beginningPart is " & beginningPart
  1083.        
  1084.         set chompped to text theOffset thru theLength of theString
  1085.         if debug ≥ 7 then log "chompped is " & chompped
  1086.         return {chompped, beginningPart}
  1087.     else
  1088.         set beginningPart to ""
  1089.         return {theString, beginningPart}
  1090.     end if
  1091.    
  1092. end answerAndChomp
  1093.  
  1094. -- ------------------------------------------------------
  1095. (*
  1096.   Delete the leading part of the string until and including theToken.
  1097. *)
  1098. on chompLeftAndTag(theString, theToken)
  1099.     global debug
  1100.     if debug ≥ 5 then log "in --- chompLeftAndTag ---"
  1101.     if debug ≥ 7 then
  1102.         log "chompLeftAndTag: theToken is " & theToken
  1103.         hexDumpFormatOne("chompLeftAndTag: theString", theString)
  1104.     end if
  1105.     set theOffset to offset of theToken in theString
  1106.     if debug ≥ 7 then log "chompLeftAndTag: theOffset is " & theOffset & " in hex is " & integerToHex(theOffset)
  1107.     set theLength to length of theString
  1108.     if debug ≥ 7 then log "chompLeftAndTag: theLength is " & theLength & " in hex is " & integerToHex(theLength)
  1109.    
  1110.     if theOffset > 0 then
  1111.         -- Do we have any more of the string to return?
  1112.         if (theOffset + (length of theToken)) ≤ length of theString then
  1113.             set chompped to text (theOffset + (length of theToken)) thru theLength of theString
  1114.         else
  1115.             set chompped to ""
  1116.         end if
  1117.         if debug ≥ 7 then log "chompLeftAndTag: length of chompped is " & integerToHex(length of chompped) & "; chompped is " & chompped
  1118.         return chompped
  1119.     else
  1120.         return ""
  1121.     end if
  1122. end chompLeftAndTag
  1123.  
  1124. -- ------------------------------------------------------
  1125. on convertToHTML(theData)
  1126.     global debug
  1127.     if debug ≥ 3 then log "in --- convertToHTML ---" & return & "  Try to send back HTML. the processed data in variable theData is " & theData
  1128.     try
  1129.         set clipboardDataQuoted to quoted form of theData
  1130.        
  1131.         if debug ≥ 1 then
  1132.             log "  convertToHTMLz: .... data soon to be returned ...." & return & "clipboardDataQuoted is " & return & clipboardDataQuoted
  1133.             hexDumpFormatOne("clipboardDataQuoted", clipboardDataQuoted)
  1134.         end if
  1135.         -- make hex string as required for HTML data on the clipboard
  1136.         set toUnix to "/bin/echo -n " & clipboardDataQuoted & " | hexdump -ve '1/1 \"%.2x\"'"
  1137.         if debug ≥ 5 then printHeader("  convertToHTMLz: toUnix to convert to hex", toUnix)
  1138.         set fromUnix to do shell script toUnix
  1139.        
  1140.         if debug ≥ 5 then printHeader("  convertToHTMLz: fromUnix", fromUnix)
  1141.        
  1142.         if debug ≥ 5 then
  1143.             log "  convertToHTMLz: displaying original string -- so we can tell if it converted successfully. "
  1144.             --hexDumpFormatOne("fromUnix", fromUnix)
  1145.         end if
  1146.     on error errMsg number n
  1147.         log "  convertToHTMLz: ==> convert to hex string failed. " & errMsg & " with number " & n
  1148.         set fromUnix to ""
  1149.     end try
  1150.     if debug ≥ 4 then log "bye from  -.- convertToHTML -.-"
  1151.     return fromUnix
  1152. end convertToHTML
  1153.  
  1154. -- ------------------------------------------------------  
  1155. (*
  1156. Yvan Koenig
  1157. https://macscripter.net/viewtopic.php?id=43133
  1158. *)
  1159. on findExtension(inputFileName)
  1160.     global debug
  1161.     if debug ≥ 5 then log "in ~~~ findExtension ~~~"
  1162.     set fileName to inputFileName as string
  1163.     set saveTID to AppleScript's text item delimiters
  1164.     set AppleScript's text item delimiters to {"."}
  1165.     set theExt to last text item of fileName
  1166.     set AppleScript's text item delimiters to saveTID
  1167.     --log "theExt is " & theExt
  1168.     if theExt ends with ":" then set theExt to text 1 thru -2 of theExt
  1169.     if debug ≥ 5 then log "theExt is " & theExt
  1170.     return theExt
  1171. end findExtension
  1172.  
  1173. -- ------------------------------------------------------
  1174. (*
  1175. length of inputLfBuffer & " in hex " & integerToHex(length of inputLfBuffer)
  1176. *)
  1177. on getIntegerAndHex(aNumber)
  1178.     global debug
  1179.     if debug ≥ 5 then log "in ~~~ getIntegerAndHex ~~~"
  1180.    
  1181.     return aNumber & " in Hex " & integerToHex(aNumber)
  1182. end getIntegerAndHex
  1183.  
  1184. -- ------------------------------------------------------
  1185. (*
  1186.   find the html title in the given web page.
  1187.  
  1188.   retrieve the file pointed to by the URL so we can
  1189.             get the title. Note: <title> can have attributes.  Example:
  1190.                
  1191.             <title data-test-page-title="Parallels Desktop Lite on the Mac App Store"
  1192.             >‎Parallels Desktop Lite on the Mac App Store</title>
  1193.  
  1194. *)
  1195. on getTitle(theURL)
  1196.     global debug
  1197.     global droppedFileName
  1198.     set lf to character id 10
  1199.    
  1200.     if debug ≥ 5 then log "in ~~~ getTitle ~~~"
  1201.     if debug ≥ 1 then log "  getTitle: ----------------------- " & theURL & " -----------------------"
  1202.     if (text 1 thru (length of "http:") of theURL is "http:") or (text 1 thru (length of "https:") of theURL is "https:") then
  1203.         -- found url we can process
  1204.         if debug ≥ 5 then log "getTitle: We can process this URL since it begins with http or https." & return & "  " & theURL
  1205.     else
  1206.         log "==> getTitle: we cannot process this url " & theURL & return & "  we will return what we received."
  1207.         return theURL --------------------------------->
  1208.     end if
  1209.    
  1210.     -- Example:
  1211.     -- curl --silent --location --max-time 10 <URL>
  1212.     set toUnix to "curl --silent --location --max-time 10 " & quoted form of theURL
  1213.     if debug ≥ 2 then log "  getTitle: what we will use to retrieve the Url. toUnix  is " & return & "  " & toUnix
  1214.     try
  1215.         if debug ≥ 2 then log "  getTitle: reading link file to get title"
  1216.         set fromUnix to do shell script toUnix
  1217.         -- enough data returned to have a title in it?
  1218.         if debug ≥ 2 then
  1219.             log "  getTitle: (length of fromUnix)  is " & (length of fromUnix)
  1220.            
  1221.             log "  getTitle: length of  (\"<title" & "</title>\")) is " & (length of ("<title" & "</title>"))
  1222.         end if
  1223.         if (length of fromUnix) < (length of ("<title" & "</title>")) then
  1224.             log "==> getTitle: site didn't return any data " & theURL & return & "  we will return what ee received."
  1225.             return theURL --------------------------------->
  1226.         end if
  1227.         if debug ≥ 2 then
  1228.             printHeader("  getTitle: fromUnix", fromUnix)
  1229.             -- may not be working with an HTLM document, so thefound title may be too long or confused.
  1230.             log "  getTitle: how far?..."
  1231.         end if
  1232.         -- there could be some bagage with the <title
  1233.         set actualTagData to tagContent(fromUnix, "<title", "</title>")
  1234.         -- Find what we will actually display in the title.
  1235.         -- Fix up gotchas.             
  1236.         if debug ≥ 2 then
  1237.             log "  getTitle: actualTagData  is ->" & actualTagData & "<-"
  1238.             hexDumpFormatOne("  getTitle: actualTagData (title)", actualTagData)
  1239.         end if
  1240.        
  1241.         if actualTagData is "" then
  1242.             set actualTagData to theURL
  1243.         else if length of actualTagData > 140 then
  1244.             if debug ≥ 2 then log "  getTitle: length of actualTagData is " & length of actualTagData & "which is too long.  Truncated."
  1245.             set actualTagData to theURL
  1246.             -- curl https://appleid.apple.com returns <title>403 Forbidden</title>
  1247.             -- which is misleading.
  1248.             -- will be extraneous characters in the title now since we haven't yet filtered them out.
  1249.         else if actualTagData contains "403" and actualTagData contains "Forbidden" then
  1250.             if debug ≥ 2 then log "  getTitle:  found 403 web page."
  1251.             set actualTagData to theURL
  1252.             -- <title>Sign In - Apple</title>
  1253.             -- got a post from the lounge.
  1254.         else if actualTagData contains "Sign In - Apple" then
  1255.             if debug ≥ 2 then log "  getTitle:  got 'Sign In - Apple' from a lounge page."
  1256.             set actualTagData to theURL
  1257.         else
  1258.             -- there could be some attributes within the <title> tag.
  1259.             -- or there could not be
  1260.             -- could an attribute have a > in it? doubtful. should be escaped.
  1261.             try
  1262.                 if debug ≥ 2 then log "  getTitle: looks like a normalist title."
  1263.                 -- find where <title ends
  1264.                 set whereToEnd to (offset of ">" in actualTagData)
  1265.                 if debug ≥ 2 then log "  getTitle: whereToEnd is " & whereToEnd
  1266.                 set whereToBegin to whereToEnd + (length of ">")
  1267.                 if debug ≥ 2 then
  1268.                     log "  getTitle: whereToBegin is " & whereToBegin
  1269.                     hexDumpFormatOne("  getTitle: actualTagData", actualTagData)
  1270.                 end if
  1271.                 set actualTagData to text whereToBegin thru (length of actualTagData) of actualTagData
  1272.                 if debug ≥ 2 then log "  getTitle: actualTagData is " & actualTagData
  1273.             on error theErrorMessage number theErrorNumber
  1274.                 log "  getTitle: ==>No ending greater than (>) for title. Badly contructed html." & return & "message is " & theErrorMessage & "error number " & theErrorNumber
  1275.                 set actualTagData to actualTagData
  1276.                 -- no need to repair.  It's not our page.
  1277.             end try
  1278.            
  1279.             -- found line-end in title.  caused confustion.
  1280.             -- note: this is new data and the multiple line-ends have not been
  1281.             -- filtered out.
  1282.             -- some joker had a line-end in the title!
  1283.             if debug ≥ 3 then
  1284.                 log "  getTitle: actualTagData (title) has been chanaged which is  " & actualTagData
  1285.                 hexDumpFormatOne("  getTitle: actualTagData (title)", actualTagData)
  1286.             end if
  1287.             set actualTagData to alterString(actualTagData, return & lf, lf)
  1288.             set actualTagData to alterString(actualTagData, return, lf)
  1289.             set actualTagData to adjustLF(actualTagData)
  1290.             if debug ≥ 2 then
  1291.                 log "  getTitle: actualTagData (title) has been chanaged which is  " & actualTagData
  1292.                 hexDumpFormatOne("  getTitle: actualTagData (title)", actualTagData)
  1293.             end if
  1294.            
  1295.         end if
  1296.     on error errMsg number n
  1297.         display dialog "  getTitle: ==> Error occured when looking for title. " & errMsg & " with number " & n & return & "  " & droppedFileName & return & "  " & theURL giving up after 10
  1298.         log "  getTitle: ==> Error occured when looking for title. " & errMsg & " with number " & n
  1299.         set actualTagData to theURL
  1300.     end try
  1301.     return actualTagData
  1302. end getTitle
  1303. -- ------------------------------------------------------
  1304. (*
  1305.   http://krypted.com/mac-os-x/to-hex-and-back/
  1306.                0    2    4    6    8    a    c    e     0 2 4 6 8 a c e
  1307. 0000000:   3c 703e 5369 6d70 6c65 2070 7574 2c20   <p>Simple put,
  1308.             *)
  1309. on hexDumpFormatOne(textMessage, hex)
  1310.     global debug
  1311.    
  1312.     set aNul to character id 1
  1313.    
  1314.     if debug ≥ 7 then log "in ~~~ hexDumpFormatOne ~~~"
  1315.     if debug ≥ 8 then log "    hexDumpFormatOne: input string is " & return & hex
  1316.    
  1317.     -- -r -p
  1318.     set displayValue to aNul & hex
  1319.     set toUnix to "/bin/echo -n " & (quoted form of displayValue) & " | xxd  "
  1320.     if debug ≥ 8 then log "    hexDumpFormatOne: toUnix is " & toUnix
  1321.    
  1322.     try
  1323.         set fromUnix to do shell script toUnix
  1324.        
  1325.         -- two hex digits
  1326.         set displayText to replaceCharacter(fromUnix, 10, "  ")
  1327.         if debug ≥ 8 then
  1328.             log "    hexDumpFormatOne: " & return & displayText
  1329.             log "    hexDumpFormatOne: length of displayText is " & length of displayText
  1330.         end if
  1331.         -- one character
  1332.         set displayText to replaceCharacter(displayText, 51, " ")
  1333.         if debug ≥ 8 then
  1334.             log "    hexDumpFormatOne: " & return & displayText
  1335.             log "    hexDumpFormatOne: almost there ..... length of displayText is " & length of displayText
  1336.         end if
  1337.         log "variable " & textMessage & " in hex is " & return & "         0    2    4    6    8    a    c    e     0 2 4 6 8 a c e" & return & displayText
  1338.     on error errMsg number n
  1339.         log "    hexDumpFormatOne: ==> convert hex string to string failed. " & errMsg & " with number " & n
  1340.     end try
  1341.     if debug ≥ 8 then
  1342.         log "leaving ~.~ hexDumpFormatOne ~.~"
  1343.     end if
  1344. end hexDumpFormatOne
  1345.  
  1346. -- ------------------------------------------------------
  1347. on hexDumpFormatZero(textMessage, hex)
  1348.     global debug
  1349.     if debug ≥ 7 then log "in ~~~ hexDumpFormatZero ~~~"
  1350.     if debug ≥ 8 then log "input string is " & hex
  1351.     -- -r -p
  1352.     set toUnix to "/bin/echo -n " & (quoted form of hex) & " | xxd  "
  1353.     if debug ≥ 8 then log "toUnix is " & toUnix
  1354.     try
  1355.         set displayText to do shell script toUnix
  1356.        
  1357.         log "variable " & textMessage & " in hex is " & return & "         0    2    4    6    8    a    c    e     0 2 4 6 8 a c e" & return & displayText
  1358.     on error errMsg number n
  1359.         log "==> convert hex string to string failed. " & errMsg & " with number " & n
  1360.     end try
  1361. end hexDumpFormatZero
  1362.  
  1363. -- ------------------------------------------------------
  1364. (*
  1365. https://macscripter.net/viewtopic.php?id=43713
  1366.   *)
  1367. on integerToHex(nDec)
  1368.     global debug
  1369.     if debug ≥ 5 then log "in ~~~ integerToHex ~~~"
  1370.     try
  1371.         set nHex to do shell script "perl -e 'printf(\"%X\", " & nDec & ")'" --> "F0"
  1372.     on error errMsg number n
  1373.         log "==> convert integer to hex. " & errMsg & " with number " & n
  1374.         set nHex to ""
  1375.     end try
  1376.     return nHex
  1377. end integerToHex
  1378.  
  1379. -- ------------------------------------------------------
  1380. (*
  1381.  
  1382. https://stackoverflow.com/questions/55838252/minimum-value-that-not-zero
  1383.        set m to get minimumPositiveNumber from {10, 2, 0, 2, 4}
  1384.     log "m is " & m
  1385.     set m to minimumPositiveNumber from {0, 0, 0}
  1386.     log "m is " & m
  1387. *)
  1388. on minimumPositiveNumber from L
  1389.     global debug
  1390.     if debug ≥ 5 then log "in ~~~ minimumPositiveNumber ~~~"
  1391.     local L
  1392.    
  1393.     if L = {} then return null
  1394.    
  1395.     set |ξ| to 0
  1396.    
  1397.     repeat with x in L
  1398.         set x to x's contents
  1399.         if (x < |ξ| and x ≠ 0) ¬
  1400.             or |ξ| = 0 then ¬
  1401.             set |ξ| to x
  1402.     end repeat
  1403.    
  1404.     |ξ|
  1405. end minimumPositiveNumber
  1406.  
  1407. -- ------------------------------------------------------
  1408. (*
  1409.   makeCaseUpper("Now is the time, perhaps, for all good men")
  1410. *)
  1411. on makeCaseUpper(theString)
  1412.     global debug
  1413.     if debug ≥ 5 then log "in ~~~ makeCaseUpper ~~~"
  1414.     set UC to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1415.     set LC to "abcdefghijklmnopqrstuvwxyz"
  1416.     set C to characters of theString
  1417.     repeat with ch in C
  1418.         if ch is in LC then set contents of ch to item (offset of ch in LC) of UC
  1419.     end repeat
  1420.     return C as string
  1421. end makeCaseUpper
  1422.  
  1423. -- ------------------------------------------------------
  1424. on postToCLipboard(pleasePost)
  1425.     global debug
  1426.     if debug ≥ 5 then log "in ~~~ postToCLipboard ~~~"
  1427.     try
  1428.         -- osascript -e "set the clipboard to «data HTML${hex}»"     
  1429.         set toUnixSet to "osascript -e \"set the clipboard to «data HTML" & pleasePost & \""
  1430.         if debug ≥ 5 then log "  postToCLipboard: toUnixSet is " & printHeader("toUnixSet", toUnixSet)
  1431.        
  1432.         set fromUnixSet to do shell script toUnixSet
  1433.         if debug ≥ 5 then log "  postToCLipboard: fromUnixSet is " & fromUnixSet
  1434.        
  1435.     on error errMsg number n
  1436.         log "  postToCLipboard: ==> We tried to send back HTML data, but failed. " & errMsg & " with number " & n
  1437.     end try
  1438.     -- see what ended up on the clipboard
  1439.     set theList2 to clipboard info
  1440.     if debug ≥ 2 then printClipboardInfo(theList2)
  1441. end postToCLipboard
  1442.  
  1443. -- ------------------------------------------------------
  1444. on printClipboardInfo(theList)
  1445.     global debug
  1446.     if debug ≥ 5 then log "in ~~~ printClipboardInfo ~~~"
  1447.     log (clipboard info)
  1448.     log class of theList
  1449.     log "Data types on the clipboard ... "
  1450.     printList("", theList)
  1451.     log "... "
  1452. end printClipboardInfo
  1453.  
  1454. -- ------------------------------------------------------
  1455. (* Pump out the beginning of theString *)
  1456. on printHeader(theName, theString)
  1457.     global debug
  1458.     if debug ≥ 7 then
  1459.         log "in ~~~ printHeader ~~~"
  1460.         log "  printHeader: the input string for titling  is " & theName
  1461.         -- let's not culter the log
  1462.         log "  printHeader: length of the string to print is " & length of theString
  1463.     end if
  1464.     if length of theString ≤ 0 then
  1465.         log "==> no string to print"
  1466.     else
  1467.         log theName & " is " & return & text 1 thru (minimumPositiveNumber from {400, length of theString}) of theString & "<+++++++++"
  1468.     end if
  1469. end printHeader
  1470.  
  1471.  
  1472. -- ------------------------------------------------------
  1473. (*
  1474. print out the items in a list
  1475.  
  1476. *)
  1477.  
  1478. on printList(theName, splits)
  1479.     global debug
  1480.     if debug ≥ 5 then log "in ~~~ printList ~~~"
  1481.     try
  1482.         set theCount to 1
  1483.         repeat with theEntry in splits
  1484.             if debug ≥ 7 then log "printList: class of theEntry is " & class of theEntry
  1485.             set classDisplay to class of theEntry as text
  1486.             if debug ≥ 7 then "printList: classDisplay is " & classDisplay as text
  1487.             if debug ≥ 7 then log "printList: class of classDisplay is " & class of classDisplay
  1488.             if classDisplay is "list" then
  1489.                 log "    " & theName & " # " & theCount & " is " & item 1 of theEntry & "; " & item 2 of theEntry
  1490.             else
  1491.                 log "    " & theName & " # " & theCount & " is " & theEntry
  1492.             end if
  1493.             set theCount to theCount + 1
  1494.         end repeat
  1495.     on error errMsg number n
  1496.         log "printList: ==> No go in printList. " & errMsg & " with number " & n
  1497.     end try
  1498. end printList
  1499.  
  1500. -- ------------------------------------------------------
  1501. (*
  1502. StefanK in https://macscripter.net/viewtopic.php?id=43852
  1503. Replaces one or more characters based on the length of theCharacter.
  1504.  
  1505.   Big Warning!!!
  1506.   ==============
  1507.     This on block is called by hexDumpFormatOne().  
  1508.     Therefor, you may not call hexDumpFormatOne() from this on block.
  1509.     If you so so, you get yourself into an endless loop.
  1510.     Use hexDumpFormatZero() instead.
  1511.    
  1512.     script -k <output file name>
  1513.     osascript /Applications/applescriptFiles/workwithclipboardV13-HTML.app
  1514.     use Activity Monito to stop osascript
  1515.    
  1516. *)
  1517.  
  1518. on replaceCharacter(theText, theOffset, theCharacter)
  1519.     global debug
  1520.     if debug ≥ 7 then log "in ~~~ replaceCharacter ~~~"
  1521.     if debug ≥ 7 then
  1522.         log "  theOffset is " & getIntegerAndHex(theOffset) & " with theCharacter >" & theCharacter & "<  length of theText is " & getIntegerAndHex(length of theText)
  1523.         log "theText is " & theText
  1524.     end if
  1525.    
  1526.     set theOutput to theText -- ready to return if need be.
  1527.     repeat 1 times
  1528.         -- sanity checks
  1529.         if theOffset ≤ 0 then
  1530.             display dialog "No character to replace at " & theOffset & " with character " & theCharacter & " in " & theText giving up after 10
  1531.             log "==> Adjust theOffset to be wihin the string."
  1532.             exit repeat -------------- return ---------->                  
  1533.         end if
  1534.         if (theOffset - (length of theCharacter))0 then
  1535.             display dialog "Too near the front of the buffer.  " & theOffset & " with character " & theCharacter & " in " & theText giving up after 10
  1536.             log "==> Too near the front of the buffer. "
  1537.             exit repeat -------------- return ---------->
  1538.         end if
  1539.         if (theOffset + (length of theCharacter) - 1) > (length of theText) then
  1540.             display dialog "To near the end of the buffer. " & theOffset & " with character " & theCharacter & " in " & theText giving up after 10
  1541.             log "==> Too near the end of the buffer. "
  1542.             log "  " & "theOffset is " & theOffset & " with theCharacter >" & theCharacter & "<  in " & theText
  1543.             log "length of buffer is " & getIntegerAndHex(length of theText)
  1544.             exit repeat -------------- return ---------->                  
  1545.         end if
  1546.        
  1547.         if debug ≥ 7 then
  1548.             log "theOffset is " & getIntegerAndHex(theOffset)
  1549.             log "theCharacter is " & theCharacter
  1550.         end if
  1551.        
  1552.         try
  1553.             -- what if we are at the end of the buffer.  We cannot get any remainder text.
  1554.             if theOffset ≥ (length of theText) then
  1555.                 set theOutput to (text 1 thru (theOffset - 1) of theText) & theCharacter
  1556.             else
  1557.                 set theOutput to (text 1 thru (theOffset - 1) of theText) & theCharacter & (text (theOffset + (length of theCharacter)) thru -1 of theText)
  1558.             end if
  1559.         on error errMsg number n
  1560.             log "==> No go. " & errMsg & " with number " & n
  1561.             exit repeat -------------- return ---------->
  1562.         end try
  1563.     end repeat
  1564.     return theOutput
  1565. end replaceCharacter
  1566.  
  1567. -- ------------------------------------------------------
  1568. (*
  1569.    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  1570.  
  1571.   DOCTYPE contains a http link, but it's not something we want to mess with.
  1572.   Tip: The <!DOCTYPE> declaration is NOT case sensitive.
  1573.   https://www.w3schools.com/tags/tag_doctype.asp
  1574.  
  1575.   best do the parsing maually, since we will not know the casing of DOCTYPE.
  1576.   fyi: An HTML comment begins with <!–– and the comment closes with ––> .
  1577.  
  1578.  *)
  1579.  
  1580. on skipDoctype(buildHtml, theInputBuffer)
  1581.     global debug
  1582.     if debug ≥ 5 then log "in --- skipDoctype ---"
  1583.     set ourOutput to buildHtml
  1584.     set ourInput to theInputBuffer
  1585.    
  1586.     set splitDoctype to splitTextToList(ourInput, "<!")
  1587.     if (count of splitDoctype)1 then
  1588.         if debug ≥ 4 then log "skipDoctype: <! hence DOCTYPE not found."
  1589.         return {buildHtml, theInputBuffer} ------------------ <! not found -------------------->
  1590.     end if
  1591.    
  1592.     set firstWordOffset to offset of " " in (item 2 of splitDoctype)
  1593.     -- ditch trailing blank.
  1594.     set firstWordOffset to firstWordOffset - 1
  1595.     if firstWordOffset ≤ 0 then
  1596.         if debug ≥ 4 then log "skipDoctype: DOCTYPE not found."
  1597.         return {buildHtml, theInputBuffer} ------------------ <! not found -------------------->
  1598.     end if
  1599.     -- it was simple to get the header stuff at least
  1600.     set ourOutput to ourOutput & item 1 of splitDoctype
  1601.    
  1602.     set firstWord to makeCaseUpper(text 1 thru firstWordOffset of (item 2 of splitDoctype))
  1603.     if debug ≥ 4 then log "skipDoctype: firstWord is " & firstWord & "  length  of firstWord is " & length of firstWord & "  class of firstWord is " & class of firstWord
  1604.    
  1605.     if firstWord is "<!DOCTYPE" then
  1606.         -- skip over DOCTYPE tag.      
  1607.         set endOfDoctypeOffset to offset of ">" in (item 2 of splitDoctype)
  1608.         if endOfDoctypeOffset ≤ 0 then
  1609.             if debug ≥ 5 then log "skipDoctype: Closing " > " not found with DOCTYPE."
  1610.             return {buildHtml, theInputBuffer} ------------------ ">" not found ---------------->
  1611.         end if
  1612.        
  1613.         -- looks good. proceed.
  1614.         set ourOutput to ourOutput & text 1 thru endOfDoctypeOffset of (item 2 of splitDoctype)
  1615.         set ourInput to text ((length of (item 1 of splitDoctype)) + endOfDoctypeOffset + 1) thru -1 of theInputBuffer
  1616.        
  1617.     else
  1618.         if debug ≥ 4 then log "skipDoctype: DOCTYPE not found as first word."
  1619.         return {buildHtml, theInputBuffer} ---------- DOCTYPE not found ---------->
  1620.     end if
  1621.    
  1622.     if debug ≥ 4 then log "skipDoctype:" & return & "ourOutput, is " & ourOutput & return & "ourInput, is " & ourInput
  1623.    
  1624.     return {ourOutput, ourInput}
  1625. end skipDoctype
  1626.  
  1627. -- ------------------------------------------------------
  1628.  
  1629. on skipTag(buildHtml, theInputBuffer, endDelim)
  1630.     global debug
  1631.    
  1632.     if debug ≥ 5 then log "in --- skipTag ---"
  1633.     set theOutput to buildHtml
  1634.     set theInput to theInputBuffer
  1635.     if debug ≥ 4 then
  1636.         log "skipTag: length of theOutput is " & (length of theOutput) & " length of theInput is " & (length of theInput)
  1637.         log "skipTag: endDelim is ->" & endDelim & "<-"
  1638.     end if
  1639.    
  1640.     set endOfTagOffset to offset of endDelim in theInput
  1641.     -- did we find the end tag?
  1642.     if endOfTagOffset ≤ 0 then
  1643.         try
  1644.             display dialog "skipTag: tag not balanced. beginning tag is" & text 1 thru 4 of theInput & " ending tag is " & endDelim giving up after 10
  1645.             log "skipTag: ==> tag not balanced. beginning tag is" & text 1 thru 4 of theInput & " ending tag is " & endDelim
  1646.         on error errMsg number n
  1647.             log "skipTag: ==> tag not balanced." & errMsg & " with number " & n
  1648.             display dialog "skipTag: tag not balanced." giving up after 10
  1649.         end try
  1650.         -- no end tag, so consider the rest as consumed
  1651.         set theOutput to ourOutput & theInput
  1652.         set theInput to ""
  1653.         return {theOutput, theInput} -- ------------------------------------------->       
  1654.     end if
  1655.    
  1656.     -- looks good. proceed.
  1657.     set theOutput to theOutput & text 1 thru endOfTagOffset of theInput
  1658.     if endOfTagOffset < (length of theInput) then
  1659.         -- loob off tag
  1660.         set theInput to text (endOfTagOffset + 1) thru -1 of theInput
  1661.     else
  1662.         set theInput to ""
  1663.     end if
  1664.    
  1665.     if debug ≥ 4 then
  1666.         log "skipTag: length of theOutput is " & (length of theOutput) & " length of theInput is " & (length of theInput)
  1667.         printHeader("skipTag: theOutput", theOutput)
  1668.         printHeader("skipTag: theInput", theInput)
  1669.     end if
  1670.    
  1671.     return {theOutput, theInput}
  1672. end skipTag
  1673.  
  1674. -- ------------------------------------------------------
  1675. (*
  1676. splitTextToList seems to be what you are trying to do
  1677.   thisText is the input string
  1678.   delim is what to split on
  1679.  
  1680.   results returned in a list
  1681.  
  1682.   Total hack. We know splitTextToList strips of delim so add it back.
  1683. *)
  1684.  
  1685. on splitTextToList(thisText, delim)
  1686.     global debug
  1687.     if debug ≥ 5 then log "in ~~~ splitTextToList ~~~"
  1688.    
  1689.     set returnedList to textToList(thisText, delim)
  1690.     set resultArray to {}
  1691.     copy item 1 of returnedList to the end of the resultArray
  1692.    
  1693.     repeat with i from 2 to (count of returnedList) in returnedList
  1694.         set newElement to delim & item i of returnedList
  1695.         copy newElement to the end of the resultArray
  1696.     end repeat
  1697.    
  1698.     return resultArray
  1699. end splitTextToList
  1700.  
  1701. -- ------------------------------------------------------
  1702. (*
  1703.   Retrieved data between "begin" and "end" tag. Whatever is between the strings.
  1704. *)
  1705. on tagContent(theString, startTag, endTag)
  1706.     global debug
  1707.     if debug ≥ 5 then log "in ~~~ tagContent ~~~"
  1708.     try
  1709.         if debug ≥ 5 then log "tagContent:  " & return & "    startTag is ->" & startTag & "<- endTag is ->" & endTag & "<-"
  1710.         set beginningOfTag to chompLeftAndTag(theString, startTag)
  1711.         if length of beginningOfTag ≤ 0 then
  1712.             set middleText to ""
  1713.         else
  1714.             if debug ≥ 5 then printHeader("tabContent: beginningOfTag", beginningOfTag)
  1715.             set endingOffset to (offset of endTag in beginningOfTag)
  1716.            
  1717.             if endingOffset ≤ (length of endTag) then
  1718.                 set middleText to ""
  1719.             else
  1720.                 set middleText to text 1 thru (endingOffset - 1) of beginningOfTag
  1721.                 if debug ≥ 5 then printHeader("tabContent: middleText", middleText)
  1722.             end if
  1723.         end if
  1724.     on error errMsg number n
  1725.         log "tagContent: ==> finding contained text failed. " & errMsg & " with number " & n
  1726.         set middleText to ""
  1727.     end try
  1728.     if debug ≥ 5 then log "tagContent: returning with middleText is " & middleText
  1729.     return middleText
  1730. end tagContent
  1731. -- ------------------------------------------------------
  1732. (*
  1733. textToList seems to be what you are trying to do
  1734.   thisText is the input string
  1735.   delim is what to split on
  1736.  
  1737.   returns a list of strings.  
  1738.  
  1739. - textToList was found here:
  1740. - http://macscripter.net/viewtopic.php?id=15423
  1741.  
  1742. *)
  1743.  
  1744. on textToList(thisText, delim)
  1745.     global debug
  1746.     if debug ≥ 5 then log "in ~~~ textToList ~~~"
  1747.     set resultList to {}
  1748.     set {tid, my text item delimiters} to {my text item delimiters, delim}
  1749.    
  1750.     try
  1751.         set resultList to every text item of thisText
  1752.         set my text item delimiters to tid
  1753.     on error
  1754.         set my text item delimiters to tid
  1755.     end try
  1756.     return resultList
  1757. end textToList
  1758.  
  1759. -- ------------------------------------------------------
  1760.  
  1761. on trimCharacters(inputTrim, outputTrim, reduce)
  1762.     global debug
  1763.     if debug ≥ 5 then log "in ~~~ trimCharacters ~~~"
  1764.     if debug ≥ 6 then
  1765.         log "  trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
  1766.         hexDumpFormatOne("  trimCharacters: inputTrim", inputTrim)
  1767.         log "  trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
  1768.         hexDumpFormatOne("  trimCharacters: outputTrim", outputTrim)
  1769.         log "  trimCharacters: with reduce >" & reduce & "<  "
  1770.     end if
  1771.     set repCount to 1
  1772.    
  1773.     repeat while length of inputTrim ≥ 1 and text 1 thru 1 of inputTrim is " "
  1774.         set {inputTrim, outputTrim} to trimOneChar(inputTrim, outputTrim, 1, "")
  1775.         if debug ≥ 6 then
  1776.             log "  trimCharacters: repCount is " & repCount
  1777.             set repCount to repCount + 1
  1778.             log "  trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
  1779.             hexDumpFormatOne("  trimCharacters: cycling inputTrim", inputTrim)
  1780.             log "  trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
  1781.             hexDumpFormatOne("  trimCharacters: cycling outputTrim", outputTrim)
  1782.         end if
  1783.     end repeat
  1784.    
  1785.     if debug ≥ 6 then
  1786.         log "  trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
  1787.         hexDumpFormatOne("  trimCharacters: completed inputTrim", inputTrim)
  1788.         log "  trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
  1789.         hexDumpFormatOne("  trimCharacters: completed outputTrim", outputTrim)
  1790.         log "bye from  ~.~ trimCharacters ~.~"
  1791.     end if
  1792.     return {inputTrim, outputTrim}
  1793. end trimCharacters
  1794.  
  1795. -- ------------------------------------------------------
  1796. on trimOneChar(inputLf, outputTrimmed, theLfOffset, substitueCharacter)
  1797.     global debug
  1798.    
  1799.     if debug ≥ 3 then
  1800.         log "in ~~~ trimOneChar ~~~"
  1801.         hexDumpFormatOne("inputLf", inputLf)
  1802.         hexDumpFormatOne("outputTrimmed", outputTrimmed)
  1803.         log "trimOneChar: theLfOffset, is " & getIntegerAndHex(theLfOffset)
  1804.         log "trimOneChar: with substitueCharacter >" & substitueCharacter & "<  "
  1805.     end if
  1806.    
  1807.     -- check boundaries
  1808.     if theLfOffset ≤ 0 or (theLfOffset > (length of inputLf)) then
  1809.         -- We are almost done.
  1810.         if debug ≥ 3 then log "trimOneChar: no LF found."
  1811.         -- tack on any trialing stuff
  1812.         set outputTrimmed to outputTrimmed & inputLf
  1813.         set inputLf to ""
  1814.         if debug ≥ 3 then
  1815.             hexDumpFormatOne("trimOneChar: inputLf", inputLf)
  1816.             hexDumpFormatOne("trimOneChar: outputTrimmed", outputTrimmed)
  1817.         end if
  1818.         return {inputLf, outputTrimmed} ------------ return ------------>
  1819.     end if
  1820.    
  1821.     -- We need to deal with output first, so we haven't trimmed the input we need.
  1822.     if theLfOffset ≥ 2 then
  1823.         if debug ≥ 6 then log "  theLfOffset ≥ 2"
  1824.         set outputTrimmed to outputTrimmed & (text 1 thru (theLfOffset - 1) of inputLf) & substitueCharacter
  1825.     else if theLfOffset = 1 then
  1826.         if debug ≥ 6 then log "  theLfOffset = 1"
  1827.         -- no stuff before the lf
  1828.         set outputTrimmed to outputTrimmed & substitueCharacter
  1829.     end if
  1830.    
  1831.     -- deal with inputLf.
  1832.     if theLfOffset < (length of inputLf) then
  1833.         if debug ≥ 6 then log "trimOneChar:  theLfOffset < (length of inputLf) "
  1834.         -- trailing stuff
  1835.         set inputLf to text (theLfOffset + 1) thru -1 of inputLf
  1836.     else if theLfOffset is (length of inputLf) then
  1837.         if debug ≥ 6 then log "trimOneChar:  theLfOffset is (length of inputLf) "
  1838.         set inputLf to ""
  1839.     end if
  1840.    
  1841.     if debug ≥ 3 then
  1842.         hexDumpFormatOne("trimOneChar: inputLf", inputLf)
  1843.         hexDumpFormatOne("trimOneChar: outputTrimmed", outputTrimmed)
  1844.     end if
  1845.     if debug ≥ 4 then log "bye from  ~.~ trimOneChar ~.~"
  1846.     return {inputLf, outputTrimmed}
  1847.    
  1848. end trimOneChar
  1849.  
  1850. -- ------------------------------------------------------
  1851. (*
  1852.          Unix-like systems      LF      0A      \n
  1853.             (Linux, macOS)
  1854.                Microsoft Windows    CRLF    0D 0A   \r\n
  1855.                classic Mac OS       CR      0D          \r   Applescript return
  1856.   *)
  1857. on typeText(theData)
  1858.    
  1859.     global debug
  1860.     if debug ≥ 5 then log "in ~~~ typeText ~~~"
  1861.     set lf to character id 1
  1862.    
  1863.     if debug ≥ 2 then printHeader("the input  ( theData )", theData)
  1864.     -- Example: -- https://discussions.apple.com/docs/DOC-8841
  1865.     -- locate links
  1866.    
  1867.     set theOutputBuffer to adjustURLs(theData, {"https://", "http://", "<a ", "<img"})
  1868.    
  1869.     -- add paragraphs
  1870.     set theOutputBuffer to addParagraphs(theOutputBuffer)
  1871.    
  1872.     if debug ≥ 2 then log "theOutputBuffer is " & return & theOutputBuffer
  1873.     if debug ≥ 4 then log "bye from  -.- typeText -.-"
  1874.     return theOutputBuffer
  1875. end typeText
  1876.  
  1877. -- ------------------------------------------------------
  1878. (*
  1879.   find the end of an URL
  1880.        -- find the end of the HTML URL by splitting on blank or return 
  1881.     -- unsafe characters  <blank> " < > # % { } | \ ^ ~ [ ] `
  1882.     -- and line-end
  1883.     -- while # is listed as unsafe, it does appear in a url as a marker of some sort.
  1884.     -- leave it out as an ending character.
  1885.     -- https://perishablepress.com/stop-using-unsafe-characters-in-urls/
  1886.     -- the end of the clipboard string my end after the url, hence no " ", LF or CR
  1887.     -- Rember, CRLF was converted to LF above
  1888. *)
  1889. on urlEndsWHere(theInputBuffer)
  1890.     global debug
  1891.     set lf to character id 10
  1892.    
  1893.     if debug ≥ 5 then log "in  ~~~ urlEndsWHere ~~~"
  1894.     set endsWhere to {}
  1895.     -- the end of the url ends with one of the not allowed characters + line-end
  1896.     repeat with unsafeCharacter in {" ", "\"", lf, "<", ">", "%", "{", "}", "|", "\\", "^", "~", "[", "]"}
  1897.         copy (offset of unsafeCharacter in theInputBuffer) to the end of the endsWhere
  1898.     end repeat
  1899.     if debug ≥ 6 then log endsWhere
  1900.     set endOfURL to (minimumPositiveNumber from endsWhere) - 1
  1901.    
  1902.     if debug ≥ 6 then log "  urlEndsWHere: endOfURL is " & endOfURL
  1903.    
  1904.     if endOfURL ≤ 0 then
  1905.         -- We have reached the end of the input
  1906.         set theURL to theInputBuffer
  1907.         set theInputBuffer to ""
  1908.     else
  1909.         set theURL to text 1 thru endOfURL of theInputBuffer
  1910.         if debug ≥ 6 then log "  urlEndsWHere:s: from middle theURL is " & theURL
  1911.        
  1912.         set theInputBuffer to text (endOfURL + 1) thru -1 of theInputBuffer -- trim off url in front.
  1913.     end if
  1914.     return {theURL, theInputBuffer}
  1915. end urlEndsWHere
  1916.  
  1917. -- ------------------------------------------------------
  1918. (* 
  1919.  place debuging data on cipboard
  1920.  has a big side effect.  
  1921. *)
  1922. on wrapupClipboardDataSelector()
  1923.     global debug
  1924.     if debug ≥ 5 then log "in ~~~ wrapupClipboardDataSelector ~~~"
  1925.     return "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
  1926. <title>roger's troubles.html</title></head>
  1927. <body>There are apps in the Play Store to sync calendars and contacts -
  1928. search on
  1929. Smoothsync for two of the best. <br>
  1930. <br>
  1931. iCloud mail is standard IMAP and you
  1932. can access it in the mail application using the settings here:<br>
  1933. <br>
  1934.  
  1935. <a href=\"https://support.apple.com/HT202304\">https://support.apple.com/HT202304</a><br>
  1936. <br>
  1937.  
  1938. As you are using a non-Apple app to access your email or other 
  1939. facilities, you are now required to use an 'app-specific' password in
  1940. place of your normal iCloud password. In order to do this you need to
  1941. set up two-factor authentication for your Apple ID, and for this you
  1942. need to have either a Mac running El Capitan or above, or an iOS device
  1943. running iOS9 or above.<br>
  1944. <br>
  1945.  
  1946. <a href=\"https://support.apple.com/HT204915\">https://support.apple.com/HT204915</a><br>
  1947. <br>
  1948.  
  1949. <a href=\"https://support.apple.com/HT204397\">https://support.apple.com/HT204397</a><br>
  1950. <br>
  1951.  
  1952. If you are unable to set up two-factor authentication you should set up
  1953. 2-step verification and use that to create an app-specific password
  1954. (see link below) . Then go
  1955. to <a href=\"https://appleid.apple.com\">https://appleid.apple.com </a>, select 'Password and Security'; click
  1956. 'Generate an App-Specific
  1957. Password' and follow the instructions. Once you have the password, copy
  1958. it and paste it into the password field in the application instead of
  1959. your usual iCloud password. You should also keep a note of it (though
  1960. you can generate a new one if required).<br>
  1961. <br>
  1962.  
  1963. <a href=\"https://support.apple.com/kb/HT204152\">https://support.apple.com/kb/HT204152</a><br>
  1964. <br>
  1965.  
  1966. You will need to nominate a 'trusted device' - any phone capable of
  1967. receiving SMS messages. There will be a 2-day wait before you can
  1968. complete the process.<br>
  1969.  
  1970. (A particular caveat (about 2-step only) - you will be issued with a
  1971. 'Recovery Key' in case you lose your 'trusted device'. Make sure to
  1972. write this down and keep it in a safe place; if you lose both it and
  1973. your trusted device you will be permanently locked out of your ID.
  1974. You'd be surprised at the number of people who've posted here that
  1975. they've got themselves into just that position.)</body></html>"
  1976.    
  1977. end wrapupClipboardDataSelector
  1978. (* <br>
  1979. Strictly speaking all purchases
  1980. are final (after all, you can't very well return them): please see this
  1981. page for information on requesting a refund:<a href=\"https://support.apple.com/HT204084\"> https://support.apple.com/HT204084</a><br>
  1982. <br>However Apple have been known to be sympathetic in cases of
  1983. actual error, so it's possible that they may allow you a refund as a
  1984. one-off concession: but please be aware that they are under no
  1985. obligation to do so: go to<a href=\"https://www.apple.com/emea/support/itunes/contact.html\"> https://www.apple.com/emea/support/itunes/contact.html</a></span><br>
  1986. <br style=\"font-family: Arial;\">
  1987. <span style=\"font-family: Arial;\">Alternatively go to the page
  1988. suggested in the Help page linked to above:</span><a href=\"https://reportaproblem.apple.com/?s=6\"><span style=\"font-family: Arial;\"> https://reportaproblem.apple.com/?s=6</span></a></font><a href=\"https://reportaproblem.apple.com/?s=6\">
  1989. </a><br>
  1990. *)
  1991. (*  return "<html><head>
  1992. <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
  1993. <title>asc insert title in &lt;a>.html</title>
  1994. </head>
  1995. <body>
  1996. <p></p>
  1997. <p>\"Avoid phishing scams\"
  1998. <a href=\"https://support.apple.com/en-ca/HT204759\">https://support.apple.com/en-ca/HT204759</a>
  1999. </p>
  2000. <p>Lets pad the <a> tag.</p>
  2001. <p>
  2002. <a title=\"Go to W3Schools HTML section\" href=\"https://support.apple.com/en-ca/HT204759\" target=\"_blank\">https://support.apple.com/en-ca/HT204759</a>
  2003. </p>
  2004. <p>That's all folks.</p><p></p>
  2005. </body>
  2006. <html>"
  2007.     *)
  2008. (*
  2009.    
  2010.        
  2011.     "Global Lyme Alliance Reveals Several Drugs and Drug Combinations That Show Success in Treating Lyme Disease
  2012. https://globallymealliance.org/press-releases/global-lyme-alliance-reveals-several-drugs-drug-combinations-show-success-treating-lyme-disease/?utm_source=Newsletter&utm_campaign=220eebaf84-EMAIL_CAMPAIGN_2019_04_18_03_43&utm_medium=email&utm_term=0_2eb359dd6a-220eebaf84-37014111
  2013.  
  2014. https://www.omf.ngo/community-symposium-2/
  2015. Saturday, September 7, 2019
  2016. Live streamed
  2017. https://www.omf.ngo/community-symposium-2/
  2018.  
  2019.  
  2020. New OMF-funded Research Publication: A Nanoelectronics-blood-based diagnostic biomarker for ME/CFS
  2021.  
  2022. Dr. Ron Davis, OMF Scientific Advisory Board Director, explains the PNAS publication on the nanoneedle (April 29, 2019)
  2023.  
  2024. A paper describing the nanoneedle was published in the Proceedings of the National Academy of Sciences. Ronald W. Davis, PhD, is the senior author. Rahim Esfandyarpour, PhD, is the lead author. The nanoneedle is a test that measures changes in immune cells with their blood plasma as a result of salt stress. Inside the nanoneedle, the immune cells interfere with a small electric current. The change in electrical activity is directly correlated with the health of the sample. The test, which is still in a pilot phase, is based on how a person’s immune cells respond to stress. With blood samples from 40 people — 20 with ME/CFS and 20 without — the test yielded precise results, accurately flagging all patients and none of the healthy individuals.
  2025.  
  2026.  
  2027. https://www.youtube.com/watch?v=6Qn0fIV8SbE&feature=youtu.be"
  2028.    
  2029.     return "<p> </p><p> </p><p>If you are unable to set up \"two-factor authentication,\" you should set up \"2-step.\"
  2030.    
  2031.    
  2032.  
  2033.  
  2034. Run etrecheck.  The
  2035. first five runs are free.</p> "
  2036. *)
  2037.  
  2038. (* 
  2039. set the clipboard to "<html><p>As you are using a non-Apple app to access your email or other  facilities, you are now required to use an 'app-specific' password in place of your normal iCloud password. In order to do this you need to set up two-factor authentication for your Apple ID, and for this you need to have either a Mac running El Capitan or above, or an iOS device running iOS9 or above.</p><p> </p><p><a href=\"https://support.apple.com/HT204915\" target=\"_blank\">Two-factor authentication for Apple ID - Apple Support</a></p><p> </p><p><a href=\"https://support.apple.com/HT204397\" target=\"_blank\">Using app-specific passwords - Apple Support</a></p><p> </p><p>If you are unable to set up \"two-factor authentication,\" you should set up \"2-step.\"
  2040.    
  2041.    
  2042.  
  2043.  
  2044. Run etrecheck.  The
  2045. first five runs are free. Provided a report on your
  2046. machines hardware and software.  Great for diagnosing your system.  Click on the download
  2047. link at the bottom of the screen.
  2048. <a href=\"http://etrecheck.com/\" target=\"_blank\">EtreCheck</a></p><p></p>
  2049. <p></p><p>
  2050. <ol>
  2051. <li>point 1</li>
  2052. <li>point 2</li>
  2053. <li>point 3</li>
  2054. </ol>
  2055. </p>
  2056. <p>the end</p>
  2057.  
  2058. </ol></p><p>
  2059. "
  2060. *)
  2061. (*
  2062. https://www.oreilly.com/library/view/applescript-the-definitive/0596102119/re89.html
  2063.  
  2064. https://stackoverflow.com/questions/11085654/apple-script-how-can-i-copy-html-content-to-the-clipboard
  2065.  
  2066. -- user has copied a file's icon in the Finder
  2067. clipboard info
  2068. -- {{string, 20}, {«class ut16», 44}, {«class hfs », 80}, {«class
  2069.  utf8», 20}, {Unicode text, 42}, {picture, 2616}, {«class icns», 43336},
  2070. {«class furl», 62}}
  2071.  
  2072. textutil -convert html foo.rtf
  2073.  
  2074. if ((clipboard info) as string) contains "«class furl»" then
  2075.         log "the clipboard contains a file named " & (the clipboard as string)
  2076.     else
  2077.         log "the clipboard does not contain a file"
  2078.     end if
  2079.    
  2080. the clipboard       required
  2081. as  class   optional
  2082.  
  2083. tell application "Script Editor"
  2084.         activate
  2085.     end tell
  2086.    
  2087. textutil has a simplistic text to html conversion
  2088.     set clipboardDataQuoted to quoted form of theData
  2089.     log "quoted form is " & clipboardDataQuoted
  2090.    
  2091.     set toUnix to "/bin/echo -n " & clipboardDataQuoted
  2092.     set toUnix to toUnix & " | textutil -convert html -noload -nostore -stdin -stdout "
  2093.     log "toUnix is " & toUnix
  2094.     set fromUnix to do shell script toUnix
  2095.     log "fromUnix  is " & fromUnix
  2096.    
  2097.    
  2098. set s to "Today is my birthday"
  2099. log text 1 thru ((offset of "my" in s) - 1) of s
  2100. --> "Today is "
  2101.             -- text 1 thru ((offset of "my" in s) - 1) of s
  2102.             -- -1 since offset return the first character "m" position count
  2103.            
  2104. log "beginningOfTag is " & text 1 thru (minimumPositiveNumber from {200, length of beginningOfTag}) of beginningOfTag & "<+++++++++++++++++++++++"
  2105.  
  2106. https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html
  2107.  
  2108. *)
  2109.  
  2110. --mac $ hex=`echo -n "<p>your html code here</>" | hexdump -ve '1/1 "%.2x"'`
  2111. --mac $ echo $hex
  2112. --3c703e796f75722068746d6c20636f646520686572653c2f3e
  2113. --mac $ osascript -e "set the clipboard to «data HTML${hex}»"
  2114. --mac $
  2115. (*  
  2116. A sub-routine for encoding ASCII characters.  
  2117.  
  2118. encode_char("$")  
  2119. --> returns: "%24"  
  2120.  
  2121. based on:  
  2122. https://www.macosxautomation.com/applescript/sbrt/sbrt-08.html  
  2123.  
  2124. *)
  2125. (*
  2126. Lowest Numeric Value in a List
  2127.  
  2128. This sub-routine will return the lowest numeric value in a list of items. The passed list can contain non-numeric data as well as lists within lists. For example:
  2129.  
  2130. lowest_number({-3.25, 23, 2345, "sid", 3, 67})
  2131. --> returns: -3.25
  2132. lowest_number({-3.25, 23, {-22, 78695, "bob"}, 2345, true, "sid", 3, 67})
  2133. --> returns: -22
  2134.  
  2135. If there is no numeric data in the passed list, the sub-routine will return a null string ("")
  2136.  
  2137. lowest_number({"this", "list", "contains", "only", "text"})
  2138. --> returns: ""
  2139.  
  2140. https://macosxautomation.com/applescript/sbrt/sbrt-03.html
  2141.  
  2142. Here's the sub-routine:
  2143.  
  2144. *)
  2145. (*
  2146. on lowestNumber(values_list)
  2147.     set the low_amount to ""
  2148.     repeat with i from 1 to the count of the values_list
  2149.         set this_item to item i of the values_list
  2150.         set the item_class to the class of this_item
  2151.         if the item_class is in {integer, real} then
  2152.             if the low_amount is "" then
  2153.                 set the low_amount to this_item
  2154.             else if this_item is less than the low_amount then
  2155.                 set the low_amount to item i of the values_list
  2156.             end if
  2157.         else if the item_class is list then
  2158.             set the low_value to lowest_number(this_item)
  2159.             if the the low_value is less than the low_amount then ¬
  2160.                 set the low_amount to the low_value
  2161.         end if
  2162.     end repeat
  2163.     return the low_amount
  2164. end lowestNumber
  2165.  
  2166. https://lists.apple.com/archives/applescript-users/2010/Sep/msg00139.html
  2167. set list_of_values to {10, 20, 30, 40, 50, 60, 2000, 9, 3000, 4}
  2168.  
  2169. set minimum to 9.9999999999E+12
  2170. set maximum to 0
  2171. repeat with ref_to_value in list_of_values
  2172.     set the_value to contents of ref_to_value
  2173.     if the_value > maximum then set maximum to the_value
  2174.     if the_value < minimum then set minimum to the_value
  2175. end repeat
  2176.  
  2177. {minimum, maximum}
  2178.  
  2179. may do the trick.
  2180.  
  2181. Yvan KOENIG (VALLAURIS, France) lundi 13 septembre 2010 22:32:41
  2182. *)
  2183. (* https://lists.apple.com/archives/applescript-users/2010/Sep/msg00139.html
  2184. set list_of_values to {10, 20, 30, 40, 50, 60, 2000, 9, 3000, 4}
  2185.  
  2186. set minimum to 9.9999999999E+12
  2187.  
  2188. assume it's limited to positive values
  2189.  
  2190.  
  2191. on maxValue(list_of_values)
  2192.     global debug
  2193.     if debug ≥ 5 then log "in maxValue " & return & list_of_values
  2194.     set maximum to 0
  2195.     repeat with ref_to_value in list_of_values
  2196.         set the_value to contents of ref_to_value
  2197.         if the_value > maximum then set maximum to the_value
  2198.     end repeat
  2199.     if debug ≥ 5 then log maximum
  2200.     return maximum
  2201. end maxValue
  2202. *)
  2203. -- ------------------------------------------------------
  2204. (*
  2205. http://harvey.nu/applescript_url_encode_routine.html
  2206.  
  2207. on urlencode(theText)
  2208.     set theTextEnc to ""
  2209.     repeat with eachChar in characters of theText
  2210.         set useChar to eachChar
  2211.         set eachCharNum to ASCII number of eachChar
  2212.         if eachCharNum = 32 then
  2213.             set useChar to "+"
  2214.         else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
  2215.             set firstDig to round (eachCharNum / 16) rounding down
  2216.             set secondDig to eachCharNum mod 16
  2217.             if firstDig > 9 then
  2218.                 set aNum to firstDig + 55
  2219.                 set firstDig to ASCII character aNum
  2220.             end if
  2221.             if secondDig > 9 then
  2222.                 set aNum to secondDig + 55
  2223.                 set secondDig to ASCII character aNum
  2224.             end if
  2225.             set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
  2226.             set useChar to numHex
  2227.         end if
  2228.         set theTextEnc to theTextEnc & useChar as string
  2229.     end repeat
  2230.     return theTextEnc
  2231. end urlencode
  2232.  
  2233. Clipboard classes after a copy from the application.
  2234. from waterfox
  2235. (*«class HTML», 13876, «class utf8», 505, «class ut16», 1012, string, 505, Unicode text, 1010*)
  2236.  
  2237. from chrome
  2238. (*«class HTML», 748, «class utf8», 204, «class ut16», 410, string, 204, Unicode text, 408*)
  2239.  
  2240. from safari
  2241. (*«class weba», 120785, «class RTF », 70255, «class HTML», 122811, «class utf8», 3370, «class ut16», 6772, uniform styles, 47132, string, 3385, scrap styles, 8122, Unicode text, 6732, uniform styles, 47132, scrap styles, 8122*)
  2242.  
  2243. iCab
  2244. (*«class weba», 1665, «class RTF », 763, «class utf8», 121, «class ut16», 244, uniform styles, 376, string, 121, scrap styles, 62, Unicode text, 242, uniform styles, 376, scrap styles, 62*)
  2245.  
  2246. Opera
  2247. (*«class HTML», 5767, «class utf8», 150, «class ut16», 302, string, 150, Unicode text, 300*)
  2248.  
  2249. Textedit
  2250. (*«class RTF », 1136, «class utf8», 138, «class ut16», 278, uniform styles, 148, string, 138, scrap styles, 22, Unicode text, 276, uniform styles, 148, scrap styles, 22*)
  2251.  
  2252. Word
  2253. (*«class DSIG», 4, «class DOBJ», 56, «class OBJD», 244, «class RTF », 30573, «class HTML», 21160, scrap styles, 22, uniform styles, 136, string, 210, Unicode text, 420, «class PDF », 13197, picture, 154058, «class EMBS», 33280, «class LNKS», 909, «class LKSD», 244, «class OJLK», 93, «class HLNK», 1387, «class OFSC», 232, «class ut16», 422, «class DSIG», 4, «class DOBJ», 56, «class OBJD», 244, scrap styles, 22, uniform styles, 136, «class EMBS», 33280, «class LNKS», 909, «class LKSD», 244, «class OJLK», 93, «class HLNK», 1387, «class OFSC», 232*)
  2254.  
  2255. TextWrangler
  2256. (*«class utf8», 185, «class BBLM», 4, «class ut16», 372, string, 185, Unicode text, 370, «class BBLM», 4*)
  2257.  
  2258. *)
  2259.  
  2260.  
  2261.  
  2262. (*
  2263.     set the clipboard to "<html><p>As you are using a non-Apple app to access your email or other  facilities, you are now required to use an 'app-specific' password in place of your normal iCloud password. In order to do this you need to set up two-factor authentication for your Apple ID, and for this you need to have either a Mac running El Capitan or above, or an iOS device running iOS9 or above.</p><p> </p><p><a href=\"https://support.apple.com/HT204915\" target=\"_blank\">Two-factor authentication for Apple ID - Apple Support</a></p><p> </p><p><a href=\"https://support.apple.com/HT204397\" target=\"_blank\">Using app-specific passwords - Apple Support</a></p><p> </p><p>If you are unable to set up two-factor authentication you should set up 2-step \"
  2264.    
  2265.    
  2266.  
  2267.  
  2268. Run etrecheck.  The
  2269. first five runs are free. Provided a report on your
  2270. machines hardware and software.  Great for diagnosing your system.  Click on the download
  2271. link at the bottom of the screen.
  2272. <a href=\"http://etrecheck.com/\" target=\"_blank\">EtreCheck</a></p><p></p>
  2273. <p></p><p>
  2274. <ol>
  2275. <li>point 1</li>
  2276. <li>point 2</li>
  2277. <li>point 3</li>
  2278. </ol>
  2279.  </p>
  2280. <p>the end</p>
  2281. "
  2282.     *)
  2283. (*  set the clipboard to "<p>Simple put, Apple attempts
  2284. to provide all the
  2285. malware detection and removal you need in Mac OS X.</p>
  2286. <p></p><p></p><p></p>
  2287. <p>\"Effective defenses against malware and other threats\" by John Galt
  2288. <a href=\"https://discussions.apple.com/docs/DOC-8841\" target=\"_blank\">Effective
  2289. defenses against malware and ot… - Apple Community</a>
  2290. </p><pre>
  2291. code line #a
  2292. code line #b
  2293. code line #c
  2294. </pre><p> </p><p>\"Avoid phishing emails, fake 'virus' alerts, phony support calls, and other scams\"
  2295. <a href=\"https://support.apple.com/en-ca/HT204759\">Avoid phishing emails, fake
  2296. 'virus' alerts, phony support calls, and other scams - Apple Support</a>
  2297. <pre>
  2298. code line #1
  2299. code line #2
  2300. code line #3
  2301. </pre>"
  2302. *)
  2303. (*
  2304.     set the clipboard to "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
  2305. <html>
  2306.   <head>
  2307.  
  2308.     <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
  2309.     <title>asc roger's help text</title>
  2310.   </head>
  2311.   <body>
  2312.     <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
  2313.     <span style=\"font-weight: bold; font-family: Lucida Grande;\">App-Specific
  2314.       passwords</span> (copy direct,
  2315.     clean up returns)<br>
  2316.     <br>
  2317.     There are apps in the Play Store to sync calendars and contacts -
  2318.     search on
  2319.     Smoothsync for two of the best. <br>
  2320.     <br>
  2321.     iCloud mail is standard IMAP and you
  2322.     can access it in the mail application using the settings here:<br>
  2323.     <br>
  2324.     <a href=\"https://support.apple.com/HT202304\">https://support.apple.com/HT202304</a><br>
  2325.     <br>
  2326.     As you are using a non-Apple app to access your email or other&nbsp;
  2327.     facilities, you are now required to use an 'app-specific' password
  2328.     in
  2329.     place of your normal iCloud password. In order to do this you need
  2330.     to
  2331.     set up two-factor authentication for your Apple ID, and for this you
  2332.     need to have either a Mac running El Capitan or above, or an iOS
  2333.     device
  2334.     running iOS9 or above.<br>
  2335.     <br>
  2336.     <a href=\"https://support.apple.com/HT204915\">https://support.apple.com/HT204915</a><br>
  2337.     <br>
  2338.     <a href=\"https://support.apple.com/HT204397\">https://support.apple.com/HT204397</a><br>
  2339.     <br>
  2340.     If you are unable to set up two-factor authentication you should set
  2341.     up
  2342.     2-step verification and use that to create an app-specific password
  2343.     (see link below) . Then go
  2344.     to https://appleid.apple.com , select 'Password and Security'; click
  2345.     'Generate an App-Specific
  2346.     Password' and follow the instructions. Once you have the password,
  2347.     copy
  2348.     it and paste it into the password field in the application instead
  2349.     of
  2350.     your usual iCloud password. You should also keep a note of it
  2351.     (though
  2352.     you can generate a new one if required).<br>
  2353.     <br>
  2354.     <a href=\"https://support.apple.com/kb/HT204152\">https://support.apple.com/kb/HT204152</a><br>
  2355.     <br>
  2356.     You will need to nominate a 'trusted device' - any phone capable of
  2357.     receiving SMS messages. There will be a 2-day wait before you can
  2358.     complete the process.<br>
  2359.     (A particular caveat (about 2-step only) - you will be issued with a
  2360.     'Recovery Key' in case you lose your 'trusted device'. Make sure to
  2361.     write this down and keep it in a safe place; if you lose both it and
  2362.     your trusted device you will be permanently locked out of your ID.
  2363.     You'd be surprised at the number of people who've posted here that
  2364.     they've got themselves into just that position.)<br>
  2365.     <br>
  2366.     Incidentally, Mail on Snow Leopard and earlier is not recognized as
  2367.     an
  2368.     Apple application because it's pre-iCloud and doesn't have the
  2369.     necessary facilities, so it will be necessary to obtain an
  2370.     app-specific
  2371.     password for that.
  2372.   </body>
  2373. </html>
  2374.  
  2375. <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
  2376. <html>
  2377.   <head>
  2378.  
  2379.     <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
  2380.     <title>asc roger's help text</title>
  2381.   </head>
  2382.   <body>
  2383.     <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
  2384.     <span style=\"font-weight: bold; font-family: Lucida Grande;\">App-Specific
  2385.       passwords</span> (copy direct,
  2386.     clean up returns)<br>
  2387.     <br>
  2388.     There are apps in the Play Store to sync calendars and contacts -
  2389.     search on
  2390.     Smoothsync for two of the best. <br>
  2391.     <br>
  2392.     iCloud mail is standard IMAP and you
  2393.     can access it in the mail application using the settings here:<br>
  2394.     <br>
  2395.     <a href=\"https://support.apple.com/HT202304\">https://support.apple.com/HT202304</a><br>
  2396.     <br>
  2397.     As you are using a non-Apple app to access your email or other&nbsp;
  2398.     facilities, you are now required to use an 'app-specific' password
  2399.     in
  2400.     place of your normal iCloud password. In order to do this you need
  2401.     to
  2402.     set up two-factor authentication for your Apple ID, and for this you
  2403.     need to have either a Mac running El Capitan or above, or an iOS
  2404.     device
  2405.     running iOS9 or above.<br>
  2406.     <br>
  2407.     <a href=\"https://support.apple.com/HT204915\">https://support.apple.com/HT204915</a><br>
  2408.     <br>
  2409.     <a href=\"https://support.apple.com/HT204397\">https://support.apple.com/HT204397</a><br>
  2410.     <br>
  2411.     If you are unable to set up two-factor authentication you should set
  2412.     up
  2413.     2-step verification and use that to create an app-specific password
  2414.     (see link below) . Then go
  2415.     to https://appleid.apple.com , select 'Password and Security'; click
  2416.     'Generate an App-Specific
  2417.     Password' and follow the instructions. Once you have the password,
  2418.     copy
  2419.     it and paste it into the password field in the application instead
  2420.     of
  2421.     your usual iCloud password. You should also keep a note of it
  2422.     (though
  2423.     you can generate a new one if required).<br>
  2424.     <br>
  2425.     <a href=\"https://support.apple.com/kb/HT204152\">https://support.apple.com/kb/HT204152</a><br>
  2426.     <br>
  2427.     You will need to nominate a 'trusted device' - any phone capable of
  2428.     receiving SMS messages. There will be a 2-day wait before you can
  2429.     complete the process.<br>
  2430.     (A particular caveat (about 2-step only) - you will be issued with a
  2431.     'Recovery Key' in case you lose your 'trusted device'. Make sure to
  2432.     write this down and keep it in a safe place; if you lose both it and
  2433.     your trusted device you will be permanently locked out of your ID.
  2434.     You'd be surprised at the number of people who've posted here that
  2435.     they've got themselves into just that position.)<br>
  2436.     <br>
  2437.     Incidentally, Mail on Snow Leopard and earlier is not recognized as
  2438.     an
  2439.     Apple application because it's pre-iCloud and doesn't have the
  2440.     necessary facilities, so it will be necessary to obtain an
  2441.     app-specific
  2442.     password for that.
  2443.   </body>
  2444. </html>
  2445. "
  2446.  
  2447. adustDuplicateAnchorURLs("<a href=\"https://support.apple.com/en-ca/HT204759\">https://support.apple.com/en-ca/HT204759</a>")
  2448.  
  2449. adustDuplicateAnchorURLs("<a title=\"Go to W3Schools HTML section\" href=\"https://support.apple.com/en-ca/HT204759\" target=\"_blank\">https://support.apple.com/en-ca/HT204759</a>")
  2450.    
  2451. return
  2452.    
  2453. *)
  2454. (*
  2455. on trimCharacters(inputTrim, outputTrim, reduce)
  2456.     global debug
  2457.     set charactersTrimmed to ""
  2458.     if debug ≥ 3 then
  2459.         log "in ~~~ trimCharacters ~~~"
  2460.         log "  trimCharacters: length of inputTrim is " & getIntegerAndHex(length of inputTrim)
  2461.         hexDumpFormatOne("  trimCharacters: inputTrim", inputTrim)
  2462.         log "  trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
  2463.         hexDumpFormatOne("  trimCharacters: outputTrim", outputTrim)
  2464.         log "  trimCharacters: with reduce >" & reduce & "<  "
  2465.     end if
  2466.     set repCount to 1
  2467.    
  2468.     repeat while length of inputTrim ≥ 1 and text 1 thru 1 of inputTrim is reduce
  2469.         set charactersTrimmed to charactersTrimmed & reduce
  2470.         set {inputTrim, outputTrim} to trimOneChar(inputTrim, outputTrim, 1, "")
  2471.         if debug ≥ 6 then
  2472.             log "  trimCharacters: repCount is " & repCount
  2473.             set repCount to repCount + 1
  2474.             log "  trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
  2475.             hexDumpFormatOne("  trimCharacters: cycling inputTrim", inputTrim)
  2476.             log "  trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
  2477.             hexDumpFormatOne("  trimCharacters: cycling outputTrim", outputTrim)
  2478.         end if
  2479.     end repeat
  2480.    
  2481.     if debug ≥ 3 then
  2482.         log "  trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
  2483.         hexDumpFormatOne("  trimCharacters: completed inputTrim", inputTrim)
  2484.         log "  trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
  2485.         hexDumpFormatOne("  trimCharacters: completed outputTrim", outputTrim)
  2486.         log "  trimCharacters: charactersTrimmed  is " & charactersTrimmed
  2487.         log "bye from  ~.~ trimCharacters ~.~"
  2488.     end if
  2489.     return {inputTrim, outputTrim, charactersTrimmed}
  2490. end trimCharacters
  2491. *)
  2492. (*
  2493. -- ------------------------------------------------------
  2494. --  
  2495. -- print out the items in a list
  2496. --
  2497. --
  2498.  
  2499. on printList(theName, splits)
  2500.     global debug
  2501.     if debug ≥ 5 then log "in ~~~ printList ~~~"
  2502.     try
  2503.         set theCount to 1
  2504.         repeat with theEntry in splits
  2505.             --log "class of theEntry is " & class of theEntry
  2506.             set classDisplay to class of theEntry as text
  2507.             --log "classDisplay is " & classDisplay as text
  2508.             --log "class of classDisplay is " & class of classDisplay
  2509.             if classDisplay is "list" then
  2510.                 log "    " & theName & " # " & theCount & " is " & item 1 of theEntry & "; " & item 2 of theEntry
  2511.             else
  2512.                 log "    " & theName & " # " & theCount & " is " & theEntry
  2513.             end if
  2514.             set theCount to theCount + 1
  2515.         end repeat
  2516.     on error errMsg number n
  2517.         log "==> No go in printList. " & errMsg & " with number " & n
  2518.     end try
  2519. end printList
  2520. *)
  2521.  
  2522.  
  2523. (*
  2524.    
  2525.     tell application "Finder"
  2526.         --set theFiles to (files in folder (choose folder))
  2527.         --reveal theFiles
  2528.     end tell
  2529.     tell application "Finder"
  2530.         --  set theFile to (choose file)
  2531.         --reveal theFiles
  2532.     end tell
  2533.     set theFiles to {¬
  2534.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:Paralles virtual machine -<a ... - html.html", ¬
  2535.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc appleid login.txt", ¬
  2536.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example longer text conversion few line ends.txt", ¬
  2537.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example longer text conversion.txt", ¬
  2538.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with &nbsp;.html", ¬
  2539.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with <pre> with <head> \"Waterfox\".html", ¬
  2540.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with <pre> with tabs and tabs in gneral.html", ¬
  2541.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with <pre>.html", ¬
  2542.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with lf & <pre>.html", ¬
  2543.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list.html", ¬
  2544.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list.txt", ¬
  2545.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test \"Waterfox\".html", ¬
  2546.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test with no begin title.html", ¬
  2547.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test with no end title.html", ¬
  2548.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test with title.html", ¬
  2549.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test.html", ¬
  2550.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc from Roger on Jiune 11th.htm..html", ¬
  2551.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc insert title in <a>.html", ¬
  2552.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc isolate a Roger issue.html", ¬
  2553.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc link problem form Roger.html", ¬
  2554.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc list test for ASC.html", ¬
  2555.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc mangle tags via \\\".html", ¬
  2556.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc my script froze on.txt", ¬
  2557.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc roger's help text.html", ¬
  2558.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc single ul and p with links.html", ¬
  2559.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc spacing test with backslash.html", ¬
  2560.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc spacing test.html", ¬
  2561.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:links and list of numbers.txt", ¬
  2562.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:littlebittytest.html", ¬
  2563.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:roger's troubles.html", ¬
  2564.         alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:CyberDuck demo.html"}
  2565.    
  2566.    
  2567.    
  2568.    
  2569.     -- debuging for openContinued.  Displays timed display dialogs.
  2570.     set localDebug to false
  2571.     -- true displayed timed dialogs
  2572.     -- false skip debuging 
  2573.     set debugSeparator to true
  2574.     -- true place a separator between the output of dropped files
  2575.     -- false nothing is added      
  2576.    
  2577.     -- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:roger's troubles.html"
  2578.     printList("theFiles are ", theFiles)
  2579.    
  2580.     --log theFiles
  2581.     openContinued(theFiles, localDebug, debugSeparator)
  2582.    
  2583.     return 1
  2584.    
  2585.     *)
  2586.  
  2587. (* 
  2588.     set myInput to "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><header>what is in the header</head>"
  2589.     skipDoctype("", myInput)
  2590.    
  2591.     return
  2592.    
  2593.     *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement