Advertisement
rccharles

asc adjust clipboard June, 17th 2019

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