Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- This applescript converts clipboard input into a format suited for pasting into an ASC
- reply. I observed that my copies into an ASC reply were not formated that well.
- I observed that copies from a web browser were formated much better. I went about
- adjusting the clipboard copy to the format expected by a web browser for best results.
- This applescript accepts the clipboard in either
- -- 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.
- -- HTML source code identified by text containing HTML markup.
- Caveat emptor.
- run with copy from Waterfox. List of main routines.
- --- run ---
- --- common ---
- --- adjustCharacters ---
- --- adjustBrowserHTML ---
- --- adjustURLs ---
- --- skipDoctype
- --- adjustDuplicateAnchorURLs ---
- --- adjustToAscHtml ---
- --- adjustLF ---
- --- convertToHTML ---
- run with HTML as text from TextWrangler. List of main routines.
- --- run ---
- --- common ---
- --- adjustCharacters ---
- --- adjustBrowserHTML ---
- --- adjustURLs ---
- --- skipDoctype
- --- adjustDuplicateAnchorURLs ---
- --- adjustToAscHtml ---
- --- adjustLF ---
- --- adjustLF ---
- --- adjustLF() ---
- --- convertToHTML
- run with plain text from TextWrangler. List of main routines
- --- run ---
- --- common ---
- --- adjustCharacters ---
- --- adjustURLs ---
- --- addParagraphs ---
- --- convertToHTML ---
- to use:
- 1) copy command + c what data you want to convert
- 2) run this applascript by double clicking on the app.
- 3) paste command + V into an ASC reply
- 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.
- Save as an Application Bundle. Don't check any of the boxes.
- Should you experience a problem, run in the Script Editor.
- Shows how to debug via on run path. Shows items added to folder. Shows log statement.
- 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.
- For testing, run in the Script Editor.
- 1) Click on the Event Log tab to see the output from the log statement
- 2) Click on Run
- change log
- may 1, 2019 -- skip 403 forbidding title
- may 2, 2019 -- convert \" to ". the \" mysteriously appears in HTML source code input. Probably some TextEdit artifact.
- copy to TextEdit copy out of TextEdit.
- may 7, 2019 -- regressed May 2nd update. Applescript was inserting \" for display purposes into output.
- may 8, 2019 -- special processing for html class on clipboard
- https://pastebin.com/raw/Yg138YqT
- may 16,2019 -- fixed hexDumpFormatOne bugs and improved output
- may 16,2019 -- added hexDumpFormatZero
- may 19,2019 -- eliminate line breaks outside the <pre>...</pre> tags in HTML. ASC intrepreting line
- breaks as meaningful <br>
- instead of white space.simplified line break code.
- https://pastebin.com/raw/Nq08cFYH
- may 23, 2019 -- squash leading blanks in a line. #4
- may 27, 2019 -- Horizontal Ellipsis. #7
- 8230 U+2026 E2 80 A6 … Horizontal Ellipsis
- https://www.charset.org/utf-8/9
- may 28, 2019 -- decide what to do with tabs. #6
- may 29, 2019 -- filter titles. #1
- https://pastebin.com/raw/3xRYMXtd
- june 1, 2019 -- automate debugging
- June 8, 2019 -- Substitute title for duplicate links
- https://pastebin.com/raw/PYb9Bvri
- June 14, 2019 -- Substitute title for more duplicate links
- https://pastebin.com/raw/n2im5Cp5
- June 15, 2019 -- ignore DOCTYPE
- June 17, 2019 -- ignore signin title for lounge posts
- June 17, 2019 -- add "if debug" where forgotten
- June 18, 2019 -- skip image tags
- enhancements:
- -- get pdf title
- -- ignore <head>
- Author: rccharles
- Copyright 2019 rccharles
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- *)
- -- Gets invoked here when you run in AppleScript editor or double click on the app icon.
- on run
- global debug
- global squashRedundentURL
- global droppedFileName
- -- 3 and 6 are good to use
- set debug to 0
- -- 0 no debugging
- -- 1 displays input and output to this routine & names of dropped files
- -- 2 moderate
- -- 3 display I'm here for important "on" blocks
- -- 4 display important data in important "on" blocks
- -- 5 display I'm here for minor "on" blocks
- -- 6 intense
- -- 7 spewing routine "on" blocks
- -- 8 routines the spew lots of data
- -- Write a message into the event log.
- log " --- Starting on " & ((current date) as string) & " with level " & debug & " debug." & " --- "
- -- how do we process the <a> tag?
- set squashRedundentURL to true
- -- true -- get title for anchor
- -- false -- let title of anchor be the same as the link
- -- debugging
- set droppedFileName to "::: from clipboard :::"
- set lf to character id 10
- if debug ≥ 3 then log "in --- run ---"
- -- initialize clipboard for debugging run
- --set the clipboard to wrapupClipboardDataSelector()
- set theList to clipboard info
- if debug ≥ 2 then printClipboardInfo(theList)
- set cbInfo to get (clipboard info) as string
- -- Most likely, if we have HTML data in the clipboard it will be from a web browser or Word.
- if cbInfo contains "HTML" then
- if debug ≥ 2 then log "run: Working with HTML Class data from clipboard."
- set theBoard to the clipboard as «class HTML»
- 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 "
- if debug ≥ 1 then
- log "run: ...Print out plain text version of inputed HTML data from the clipboard..." & return & normalHtml
- hexDumpFormatOne("run: after converting to printable, normalHtml", normalHtml)
- end if
- set normalHtml to adjustCharacters(normalHtml)
- set returnedData to adjustBrowserHTML(normalHtml)
- if debug ≥ 2 then
- log "run: ...Print out plain text version of adjusted HTML data ..." & return & returnedData
- log "run: ...just printed plain text version"
- log "run: printed in hex"
- hexDumpFormatOne("run: returnedData", returnedData)
- end if
- set returnedData to convertToHTML(returnedData)
- try
- if debug ≥ 2 then log "returnedData is " & returnedData
- on error errStr number errorNumber
- log "run: ===> We didn't find HTML data. errStr is " & errStr & " errorNumber is " & errorNumber
- return 1
- end try
- else
- -- will work with a plain html or plain text.
- try
- if debug ≥ 2 then log "Working with plain html or plain text"
- set clipboardData to (the clipboard as text)
- if debug ≥ 2 then
- log "run: class clipboardData is " & class of clipboardData
- log "run: continuing plain html or plain text"
- end if
- if debug ≥ 1 then
- log "run: inputted clipboardData is " & clipboardData
- hexDumpFormatOne("run: inputted clipboardData", clipboardData)
- end if
- on error errStr number errorNumber
- log "run: ===> We didn't find data on the clipboard. errStr is " & errStr & " errorNumber is " & errorNumber
- 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
- return 1
- end try
- if debug ≥ 2 then log "run: calling common"
- set returnedData to common(clipboardData)
- end if
- if debug ≥ 2 then log "run: place on the clipboard returnedData is " & returnedData
- postToCLipboard(returnedData)
- -- return code
- return 0
- end run
- -- ------------------------------------------------------
- -- Folder actions.
- -- Gets invoked here when something is dropped on the folder that this script is monitoring.
- -- Right click on the folder to be monitored. services > Folder Action Settup...
- on adding folder items to this_folder after receiving added_items
- -- Write a message into the event log.
- log " --- Starting on " & ((current date) as string) & " --- "
- display dialog "TBD, some assembly required."
- end adding folder items to
- -- ------------------------------------------------------
- (*
- Gets invoked here when something is dropped on this AppleScript icon
- there seemed to be some confustion when calling the open handler directly from within run, so openContinued was created.
- *)
- on open dropped_items
- global debug
- global squashRedundentURL
- global droppedFileName
- -- see on run for details
- set debug to 1
- -- how do we process the <a> tag?
- set squashRedundentURL to true
- -- true -- get title for anchor
- -- false -- let title of anchor be the same as the link
- -- for debugging error message
- set droppedFileName to ""
- -- debuging for openContinued. Displays timed display dialogs.
- set localDebug to false
- -- true displayed timed dialogs
- -- false skip debuging
- set debugSeparator to true
- -- true place a separator between the output of dropped files
- -- false nothing is added
- -- Write a message into the event log.
- log " --- Starting on " & ((current date) as string) & " --- "
- if debug ≥ 3 then log "in --- open ---"
- openContinued(dropped_items, localDebug, debugSeparator)
- -- we tried
- return 0
- end open
- -- ------------------------------------------------------
- (*
- there seemed to be some confustion when calling the open handler directly from within run.
- *)
- on openContinued(droppedItems, localDebug, debugSeparator)
- global debug
- global squashRedundentURL
- global droppedFileName
- if debug ≥ 3 then log "in --- openContinued ---"
- (*
- -- Debug code. let's us select all items in a folder.
- set fileName to choose file with prompt "get file"
- set droppeditems to {fileName}
- *)
- if debug ≥ 2 then log "class of droppeditems is " & class of droppedItems
- if (count of droppedItems) is 1 then
- set substitueString to (count of droppedItems) & " item."
- else
- set substitueString to (count of droppedItems) & " items."
- end if
- display dialog "You dropped " & substitueString & return & " Caveat emptor. You have been warned." giving up after 6
- set totalFileData to ""
- repeat with droppedItem in droppedItems
- set droppedFileName to droppedItem as string
- if debug ≥ 1 then
- log return & "... The droppedItem is " & (droppedItem as string) & " ... " & return
- if localDebug then display dialog "processing file " & (droppedItem as string) giving up after 3
- log "class = " & class of droppedItem
- end if
- set extIs to findExtension(droppedItem)
- set extIsU to makeCaseUpper(extIs)
- if extIsU is "HTML" or extIsU is "HTM" or extIsU is "TEXT" or extIsU is "TXT" then
- try
- set theFileString to droppedItem as string
- if localDebug is true and debug is 0 then display dialog "theFileString " & return & theFileString giving up after 3
- set theFile to open for access file theFileString
- set allOfFile to read theFile
- close access theFile
- on error theErrorMessage number theErrorNumber
- log "==> " & theErrorMessage & "error number " & theErrorNumber
- close access theFile
- end try
- if debug ≥ 2 then printHeader("read from file ( allOfFile )", allOfFile)
- --if localDebug then display dialog "processing " giving up after 3
- if debugSeparator then
- -- get just the filename and extension
- set justTheName to last item of textToList(theFileString, ":")
- -- prevent your web broswer from acting on html like text
- set justTheName to alterString(justTheName, "&", "&")
- set justTheName to alterString(justTheName, "<", "<")
- set totalFileData to totalFileData & convertToHTML("<p><pre> --> " & justTheName & " <--</pre></p>")
- if localDebug then display dialog "length and data of totalFileData " & (length of totalFileData) & return & totalFileData giving up after 3
- end if
- -- returns data converted to clipboard html
- set totalFileData to totalFileData & common(allOfFile)
- if localDebug then display dialog "after length and data of totalFileData " & (length of totalFileData) & return & totalFileData giving up after 3
- else
- -- we do not support this extension
- 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
- end if
- end repeat
- postToCLipboard(totalFileData)
- if localDebug then display dialog "posted to clipboard length and data " & (length of totalFileData) & return & totalFileData giving up after 20
- -- return code
- return 0
- end openContinued
- -- ------------------------------------------------------
- on common(clipboardData)
- global debug
- if debug ≥ 3 then log "in --- common ---"
- set ht to character id 9
- set lf to character id 10
- set cbInfo to get (clipboard info) as string
- set clipboardData to adjustCharacters(clipboardData)
- (*
- -- for some crazy reason, I found hex "090a" (HT LF) in a html file.
- set clipboardData to alterString(clipboardData, ht & lf, lf)
- -- don't let Windoze confuse us. convert Return LineFeed to lf
- set clipboardData to alterString(clipboardData, return & lf, lf)
- -- might as will convert classic macOS return to lf. We will have to look for less things.
- set clipboardData to alterString(clipboardData, return, lf)
- if debug ≥ 2 then hexDumpFormatOne("change various line ends to a LF. clipboardData", clipboardData)
- *)
- -- figure out what type of data we have: plain text or html source code text.
- set paraCount to count of textToList(clipboardData, "<p")
- set endparaCount to count of textToList(clipboardData, "</p>")
- set titleCount to count of textToList(clipboardData, "<title")
- set endTitleCount to count of textToList(clipboardData, "</title>")
- set aLinkCount to count of textToList(clipboardData, "href=\"http")
- -- mangled href="http
- set mangledLinkCount to count of textToList(clipboardData, "href=\\\"http")
- set brCount to count of textToList(clipboardData, "<br>")
- if debug ≥ 2 then
- log "common: Values used to distinguish HTML source code from plain text."
- log "common: paraCount is " & paraCount
- log "common: endparaCount is " & endparaCount
- log "common: titleCount is " & titleCount
- log "common: endTitleCount is " & endTitleCount
- log "common: aLinkCount is " & aLinkCount
- log "common: brCount is " & brCount
- log "common: mangledLinkCount is " & mangledLinkCount
- end if
- -- note, textToList returns a count one greater than the actual because item one is the data before the first found entry.
- if paraCount ≥ 4 and endparaCount ≥ 3 or brCount ≥ 4 or ((titleCount is endTitleCount) and titleCount ≥ 2) or aLinkCount ≥ 3 or mangledLinkCount ≥ 3 then
- -- ASC tends to convert line-ends to either <p></p> or <p><br></p>. Isn't desireable for HTML input
- if debug ≥ 2 then log return & "common: ... found HTML input ... (in plain text format )." & return
- set clipboardData to adjustBrowserHTML(clipboardData)
- else
- if debug ≥ 2 then log "common: ... found plain Text input ..."
- set clipboardData to typeText(clipboardData)
- end if
- set readyData to convertToHTML(clipboardData)
- if debug ≥ 4 then log "bye, bye from -.- common -.-"
- return readyData
- end common
- -- ------------------------------------------------------
- (* add paragraphs *)
- on addParagraphs(theOutputBuffer)
- global debug
- if debug ≥ 3 then log "in --- addParagraphs ---"
- set lf to character id 10
- -- start the theOutputBuffer with a paragraph tag. We are taking a simple approach at this time.
- set theOutputBuffer to "<p>" & theOutputBuffer
- -- LF
- -- Remember CRLF was changed to LF above and CR was chanaged to LF above.
- -- we don't want no Windoze problems
- set theOutputBuffer to alterString(theOutputBuffer, lf & lf, "</p><p> </p><p>")
- -- Does the string end with a dangling paragraph?
- if debug ≥ 5 then
- log "length of theOutputBuffer is " & length of theOutputBuffer
- end if
- if (length of theOutputBuffer) > (length of "</p>") then
- if text ((length of theOutputBuffer) - 2) thru (length of theOutputBuffer) of theOutputBuffer is "<p>" then
- set theOutputBuffer to text 1 thru ((length of theOutputBuffer) - 3) of theOutputBuffer
- else if text ((length of theOutputBuffer) - 2) thru (length of theOutputBuffer) of theOutputBuffer is not "</p>" then
- set theOutputBuffer to theOutputBuffer & "</p>"
- end if
- end if
- if debug ≥ 4 then log "bye from -.- addParagraphs -.-"
- return theOutputBuffer
- end addParagraphs
- -- ------------------------------------------------------
- (*
- We received HTML class data on the clipboard. This is the manager.
- At this point, we expect only LFs in the text.
- *)
- on adjustBrowserHTML(normalHtml)
- global debug
- if debug ≥ 3 then log "in --- adjustBrowserHTML ---"
- set lf to character id 10
- set alteredHTML to adjustURLs(normalHtml, {"https://", "http://", "<a ", "<img"})
- set alteredHTML to adjustToAscHTML(alteredHTML)
- if debug ≥ 4 then log "bye from -.- adjustBrowserHTML -.-"
- return alteredHTML
- end adjustBrowserHTML
- -- ------------------------------------------------------
- (*
- Symbol Meaning Hex Used
- CR Carriage Return 0d classic Macintosh
- LF Line Feed 0a UNIX
- CR/LF Carriage Return/Line Feed 0d0a MS-DOS, Windows, OS/2
- 8230 U+2026 E2 80 A6 … Horizontal Ellipsis
- https://www.charset.org/utf-8/9
- …
- https://www.toptal.com/designers/htmlarrows/punctuation/horizontal-ellipsis/
- *)
- on adjustCharacters(normalHtml)
- global debug
- set ht to character id 9 -- horizontal tab
- set lf to character id 10
- set ellipsis1 to character id 226
- set ellipsis2 to character id 128
- set ellipsis3 to character id 166
- if debug ≥ 3 then log "in --- adjustCharacters() ---"
- -- for some reason web broswers are having difficulty with utf-8 E2 80 A6
- -- so convert to a HTML entity. does work in <pre>
- set normalHtml to alterString(normalHtml, ellipsis1 & ellipsis2 & ellipsis3, "…")
- -- don't let Windoze confuse us. convert Return LineFeed to lf
- set normalHtml to alterString(normalHtml, return & lf, lf)
- -- might as will convert classic macOS return to lf. We will have to look for less things.
- set normalHtml to alterString(normalHtml, return, lf)
- if debug ≥ 3 then hexDumpFormatOne("adjustCharacters: after altering characters normalHtml", normalHtml)
- return normalHtml
- end adjustCharacters
- -- ------------------------------------------------------
- (*
- Is the displayed title the same as the href URL?
- <a href="https://support.apple.com/en-ca/HT204759">https://support.apple.com/en-ca/HT204759</a>
- -- span tag; blank before https:
- <a href="https://reportaproblem.apple.com/?s=6"><span style="font-family: Arial;"> https://reportaproblem.apple.com/?s=6</span></a>
- -- blank display field
- <a href="https://reportaproblem.apple.com/?s=6"></a>
- -- guard against http in DOCTYPE.
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- https://html.com/tags/doctype/
- *)
- on adjustDuplicateAnchorURLs(anchorTagInput)
- global debug
- global squashRedundentURL
- set lf to character id 10
- if debug ≥ 3 then log "in --- adjustDuplicateAnchorURLs ---"
- -- reduce LFs in title
- set anchorTagString to alterString(anchorTagInput, lf, " ")
- if debug ≥ 2 then hexDumpFormatOne(" adjustDuplicateAnchorURLs: anchorTagString", anchorTagString)
- -- Does the user want us to get the title for duplicate URLs?
- if squashRedundentURL is false then
- return anchorTagString -- --------- ignore duplicates ---------->
- end if
- set splitList to textToList(anchorTagString, "href=")
- if debug ≥ 4 then printList("adjustDuplicateAnchorURLs: splitList", splitList)
- -- Deal with document anchor points. <a href="#refunds">Refunds</a>
- if (count of splitList) ≤ 1 then
- -- we didn't find a linking anchor point. no href.
- return anchorTagString -- --------- not a linking <a> tag ---------->
- end if
- -- get href url.
- set hrefURL to tagContent(item 2 of splitList, "\"", "\"")
- if debug ≥ 2 then log " adjustDuplicateAnchorURLs: hrefURL is " & hrefURL
- -- get display information
- set titleURL to tagContent(item 2 of splitList, ">", "</a>")
- if debug ≥ 2 then log " adjustDuplicateAnchorURLs: titleURL is " & titleURL
- -- for the display text to contain an URL it must be at least "http://" characters long.
- if (length of titleURL) ≤ (length of "http://") then
- -- we didn't find a url in the display text
- return anchorTagString -- --------- no url in display text ---------->
- end if
- -- http or https?
- set aTagSeparator to ""
- -- note, in case the delimiter isn't found all the text is returen in item # 1
- set splitURLhttp to splitTextToList(titleURL, "http://")
- if debug ≥ 2 then log "count of splitURLhttp is " & (count of splitURLhttp)
- if debug ≥ 2 then printList("adjustDuplicateAnchorURLs: splitURLhttp is", splitURLhttp)
- set splitURLhttps to splitTextToList(titleURL, "https://")
- if debug ≥ 2 then log "adjustDuplicateAnchorURLs: count of splitURLhttps is " & (count of splitURLhttps)
- if debug ≥ 2 then printList("adjustDuplicateAnchorURLs: splitURLhttps is", splitURLhttps)
- set splitURLhttpLength to length of (item 1 of splitURLhttp)
- set LengthsplitURLhttps to length of (item 1 of splitURLhttps)
- -- did we find the http:// header?
- if (count of splitURLhttp) ≥ 2 then
- if debug ≥ 2 then log "adjustDuplicateAnchorURLs: http found"
- set aTagSeparator to (item 1 of splitURLhttp)
- -- might be a little too general. allows blanks and line ends in the middle of the url
- -- when I have seen them only in front and end.
- set {titleURL, trailingText} to urlEndsWHere(item 2 of splitURLhttp)
- -- did we find the https:// header? Hence, item # 2 will be present containing what's after
- -- https://
- else if (count of splitURLhttps) ≥ 2 then
- if debug ≥ 2 then log "adjustDuplicateAnchorURLs: https found"
- set aTagSeparator to (item 1 of splitURLhttps)
- -- ditto
- set {titleURL, trailingText} to urlEndsWHere(item 2 of splitURLhttps)
- else
- if debug ≥ 2 then log "adjustDuplicateAnchorURLs: no url in display text"
- -- RW puts a blank character in front of the display string :-(
- if length of titleURL > 0 then
- if debug ≥ 2 then log "adjustDuplicateAnchorURLs: commentry title text"
- return anchorTagString -- --------- ignore duplicates ---------->
- end if
- ---------------------------------------- need to adjust above ..............
- -- text in display text, so insert title from hrefURL.
- -- some web browsers use hrefURL
- set titleURL to hrefURL
- end if
- if debug ≥ 2 then log "adjustDuplicateAnchorURLs: length of aTagSeparator is " & (length of aTagSeparator) & "aTagSeparator is ->" & aTagSeparator & "<-"
- -- make the comparison
- if debug ≥ 2 then log " ajdustDuplicateAnchorURLs: hrefURL is " & return & hrefURL & return & " titleURL is " & return & titleURL
- if hrefURL is not titleURL then
- if debug ≥ 2 then "adustDuplicateAnchorURLs: href and display text are different."
- return anchorTagString -- --------- assume we have the title ---------->
- end if
- -- They are the same
- if debug ≥ 2 then log " adjustDuplicateAnchorURLs: href and title are the same."
- set gotTitle to getTitle(hrefURL)
- if debug ≥ 2 then log " adustDuplicateAnchorURLs: gotTitle is " & gotTitle
- -- build anchor tag.
- set anchorTrailer to textToList(item 2 of splitList, ">")
- if debug ≥ 4 then printList("adjustDuplicateAnchorURLs: anchorTrailer", anchorTrailer)
- set anchorTagOutput to (item 1 of splitList) & " href=" & item 1 of anchorTrailer & ">" & aTagSeparator & gotTitle & trailingText & "</a>"
- if debug ≥ 2 then log " adjustDuplicateAnchorURLs: anchorTagOutout is " & anchorTagOutput
- return anchorTagOutput
- end adjustDuplicateAnchorURLs
- -- ------------------------------------------------------
- -- called for HTML processing
- on adjustLF(theBuffer)
- global debug
- set ht to character id 9
- set lf to character id 10
- if debug ≥ 3 then log "in --- adjustLF() ---"
- if debug ≥ 2 then hexDumpFormatOne(" adjustLF: input from theBuffer", theBuffer)
- set numberOfLf to 1 -- for debuggin so we can display loop count
- set inputLfBuffer to theBuffer -- now, input data
- set outputBuildLf to "" -- output data
- -- copy & change
- -- ditch leading LFs
- repeat while length of inputLfBuffer ≥ 2 and text 1 thru 1 of inputLfBuffer is lf
- if debug ≥ 2 then log " adjustLF: found leading lf. current length of inputLfBuffer is " & getIntegerAndHex(length of inputLfBuffer)
- -- just lob off LF
- set inputLfBuffer to text 2 thru -1 of inputLfBuffer
- if debug ≥ 2 then log " adjustLF: next text character is ->" & (text 1 thru 1 of inputLfBuffer) & "<-"
- end repeat
- -- for some crazy reason, I found hex "090a" (HT LF) in a html file.
- set inputLfBuffer to alterString(inputLfBuffer, ht & lf, lf)
- repeat until inputLfBuffer is ""
- set whereLfOffset to offset of lf in inputLfBuffer
- if debug ≥ 2 then log " adjustLF: whereLfOffset is " & whereLfOffset & " in hex " & integerToHex(whereLfOffset)
- -- get before and after characters if present.
- if whereLfOffset ≥ 2 then
- set priorCharacter to (text (whereLfOffset - 1) thru (whereLfOffset - 1) in inputLfBuffer)
- else
- set priorCharacter to ""
- end if
- if whereLfOffset ≥ (length of inputLfBuffer) then
- -- no following character
- set followingCharacter to ""
- else
- set followingCharacter to (text (whereLfOffset + 1) thru (whereLfOffset + 1) in inputLfBuffer)
- end if
- if debug ≥ 2 then log " adjustLF: priorCharacter is >" & priorCharacter & "< followingCharacter is >" & followingCharacter & "<"
- -- process the LF.
- if (whereLfOffset is 1) and ((length of inputLfBuffer) ≥ 2) then
- set inputLfBuffer to text 2 thru -1 of inputLfBuffer
- if debug ≥ 2 then log " adjustLF: leading lf. Got rid of it."
- -- nothing to move to outputBuildLf
- else if (whereLfOffset is 1) and ((length of inputLfBuffer) is 1) then
- -- we have found all theLFs to find.
- set inputLfBuffer to ""
- if debug ≥ 2 then log " adjustLF: only one character left. Got rid of it."
- else if followingCharacter is "" then
- if debug ≥ 2 then log "null"
- -- didn't we just check this? Yes, but we need to iterate somehow.
- set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, " ")
- -- just skip it, so we don't have to put anything on outputBuildLf
- else if priorCharacter is not ">" and priorCharacter is not " " and followingCharacter is lf then
- -- reduce a series of LFs to one blank
- -- the next time around the next LF will be comparing to the prior character
- -- as a blank
- if debug ≥ 2 then log " adjustLF: series of LFs"
- set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, " ")
- else if priorCharacter is " " and followingCharacter is tab then
- -- reduce a series of LFs to one blank
- -- the next time around the next LF will be comparing to the prior character
- -- as a blank
- if debug ≥ 2 then log " adjustLF: series of LFs"
- set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, "")
- set {inputLfBuffer, outputBuildLf} to trimCharacters(inputLfBuffer, outputBuildLf, tab)
- else if priorCharacter is ">" and followingCharacter is not " " then
- -- LF after HTML tag. no real need for lf here. asc tends to make these into <p></p>
- if debug ≥ 2 then log " adjustLF: found a tag"
- -- copy prior stuff
- set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, "")
- else if followingCharacter is lf then
- -- prevent double LFs.
- if debug ≥ 2 then log " adjustLF: prevent double LFs at" & getIntegerAndHex(whereLfOffset)
- set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, "")
- -- middle of text
- else if (whereLfOffset < (length of inputLfBuffer)) and followingCharacter is " " then
- -- we need to avoid double blanks
- -- purge
- if debug ≥ 2 then log " adjustLF: getting rid of lf at " & getIntegerAndHex(whereLfOffset)
- -- skip lf.
- set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, " ")
- -- get read of leading spaces. That is the spaces after the lf
- set {inputLfBuffer, outputBuildLf} to trimCharacters(inputLfBuffer, outputBuildLf, " ")
- else
- -- assume there are character before and after the LF.
- if debug ≥ 2 then log " adjustLF: punt."
- -- replace with blank
- set {inputLfBuffer, outputBuildLf} to trimOneChar(inputLfBuffer, outputBuildLf, whereLfOffset, " ")
- end if
- if debug ≥ 2 then
- hexDumpFormatOne(" adjustLF: outputBuildLf of " & numberOfLf, outputBuildLf)
- hexDumpFormatOne(" adjustLF: inputLfBuffer of " & numberOfLf, inputLfBuffer)
- end if
- -- next pass will be
- set numberOfLf to numberOfLf + 1
- end repeat
- if debug ≥ 4 then log "bye from -.- adjustLF() -.-"
- return outputBuildLf
- end adjustLF
- -- ------------------------------------------------------
- (* ASC likes to insert lots of white space into a page.
- This routine attempt to fix up the html to avoid
- all the extra white-space.
- Minimize the amount of white space inserted.
- *)
- on adjustToAscHTML(ascHtml)
- global debug
- if debug ≥ 3 then log "in --- adjustToAscHtml ---"
- set lf to character id 10
- set numberOfPres to 1
- -- In the context of HTML, LF should mostly be insignificant.
- -- Would be bad to change a LF inside the <pre> tag.
- --skip changing lf in "<pre>.
- set buildHtml to "" -- will contain the output
- if debug ≥ 2 then log "adjustToAscHTML: find <pre>s"
- -- copy & change
- if (offset of "</pre>" in ascHtml) is not 0 then
- repeat while (offset of "</pre>" in ascHtml) is not 0
- -- get text before "<pre" tag
- set splitString to item 1 of splitTextToList(ascHtml, "<pre")
- if debug ≥ 2 then
- log "adjustToAscHTML: splitString is " & splitString
- hexDumpFormatOne("adjustToAscHTML: buildHtml *before* adjustLF()", buildHtml)
- end if
- set buildHtml to buildHtml & adjustLF(splitString)
- if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: buildHtml after adjustLF()", buildHtml)
- -- lob off header text we processed
- -- while we found the text before "<pre", we still need to get it out
- -- of ascHtml
- -- & gets rid of the token ("<pre"), so fix
- set ascHtml to "<pre" & chompLeftAndTag(ascHtml, "<pre")
- -- any more <pre> tags?
- if ascHtml is "" then
- display dialog "adjustToAscHTML: HTML missing </pre> tag. possible logic error." giving up after 10
- -- none. We have already adjusted buildHtml
- exit repeat -- ------ done processing ascHtml ------>
- end if
- if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: remaining ascHtml is ", ascHtml)
- -- tack on the unaltered <pre>..</pre> stuff
- set buildHtml to buildHtml & (item 1 of splitTextToList(ascHtml, "</pre>")) & "</pre>"
- if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: buildHtml after finding </pre>", buildHtml)
- set ascHtml to chompLeftAndTag(ascHtml, "</pre>")
- if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: ascHtml end of " & numberOfPres & " pass", ascHtml)
- set numberOfPres to numberOfPres + 1
- end repeat
- -- remainder
- set buildHtml to buildHtml & adjustLF(ascHtml)
- set ascHtml to ""
- else
- -- lf's are only signigicant in <pre>...</pre>
- if debug ≥ 2 then log "adjustToAscHTML: didn't find a <pre>"
- -- all others are white space.
- set buildHtml to adjustLF(ascHtml)
- set ascHtml to "" -- input text processed
- end if
- (*
- Hack about to fix ASC interpretation of HTML.
- ASC alters the definition of a paragraph to have not space before or after the paragraph.
- A paragraph like <p></p> works like a <br>.
- Consequently, ASC converts <p> </p> to <p><br></p>, that is a
- space only paragraph to a paragraph with a <br> in it.
- the code converts one tag on a line to a line of tags.
- </ol>
- </p>
- <p>
- converted form
- </ol></p><p>
- so that means a change on </ol></p><p> converts both the multi-lines form and the single line form.
- *)
- set buildHtml to alterString(buildHtml, "<br> ", "<br>")
- -------------------- failure???
- --set buildHtml to alterString(buildHtml, "<p> ", "<p>")
- -- asc paragraphs don't generate space before and after the paragraph.
- set buildHtml to alterString(buildHtml, "</p><p></p><p></p>", "</p><p> </p><p></p>")
- set buildHtml to alterString(buildHtml, "</p><p></p><p></p>", "</p><p> </p><p></p>")
- set buildHtml to alterString(buildHtml, "</ol></p><p>", "</ol><p> </p></p><p>")
- (*
- surprisingly ASC converts <p> </p> to <p><br></p>, that is a
- space only paragraph to a paragraph with a <br> in it.
- the code converts one tag on a line to a line of tags.
- </ol>
- </p>
- <p>
- converted form
- </ol></p><p>
- so that means a change on </ol></p><p> converts both the multi-lines form and the single line form.
- *)
- --set buildHtml to alterString(buildHtml, "<p> </p>", "<p></p>")
- if debug ≥ 2 then hexDumpFormatOne("adjustToAscHTML: complete buildHtml ", buildHtml)
- if debug ≥ 4 then log "bye from -.- adjustToAscHTML -.-"
- return buildHtml
- end adjustToAscHTML
- -- ------------------------------------------------------
- (*
- example:
- Free version of Parallels for individual use:</p><p><br></p>
- <p>https://itunes.apple.com/us/app/parallels-desktop-lite/id1085114709?mt=12</p>
- <p><br></p>
- <p>Full version</p><p><a href="http://www.parallels.com/en/products/desktop/" target="_blank">
- http://www.parallels.com/en/products/desktop/</a>
- If asc find a URL outside of an a tag, it will place blank lines around the URL. No, it will not go the
- full nine yards and place an a tag around the url.
- *)
- on adjustURLs(theOriginalInputBuffer, linkList)
- -- linkList is what type of links are we searching for.
- global debug
- if debug ≥ 3 then log "in --- adjustURLs ---"
- set alteredBuffer to false
- set lf to character id 10
- set theInputBuffer to theOriginalInputBuffer
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: theInputBuffer", theInputBuffer)
- -- we end up in a lot of grief when the buffer ends without
- -- a line-end
- if text (length of theInputBuffer) thru (length of theInputBuffer) of theInputBuffer is not lf then
- -- tack LF at the end
- set alteredBuffer to true
- set theInputBuffer to theInputBuffer & lf
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: theInputBuffer", theInputBuffer)
- end if
- set buildHtml to ""
- -- DOCTYPE contains a http link, but it's not something we want to mess with.
- set {buildHtml, theInputBuffer} to skipDoctype(buildHtml, theInputBuffer)
- set countI to 1 -- variable is used for debuging.
- -- do until we have processed theInputBuffer
- repeat until theInputBuffer is ""
- if debug ≥ 2 then log " adjustURLs: at the top of theInputBuffer ........."
- set foundWhere to {}
- repeat with lookCharacters in linkList
- copy (offset of lookCharacters in theInputBuffer) to the end of the foundWhere
- try
- set tempLoc to (offset of lookCharacters in theInputBuffer)
- if debug ≥ 2 then log " adjustURLs: searching for " & lookCharacters & " found at offset " & tempLoc & " contains " & text tempLoc thru (tempLoc + ((length of lookCharacters) - 1)) of theInputBuffer
- end try
- end repeat
- if debug ≥ 2 then log foundWhere
- set foundMarkerOffset to (minimumPositiveNumber from foundWhere)
- -- figure out what type of marker we got?
- -- None. Reached the end of the data without finding one.
- if foundMarkerOffset ≤ 0 then
- -- we are done
- if debug ≥ 2 then log " adjustURLs: Found all links."
- set buildHtml to buildHtml & theInputBuffer
- if debug ≥ 2 then printHeader(" adjustURLs: buildHTML", buildHtml)
- set theInputBuffer to ""
- exit repeat -- ------ done processing theInputBuffer ------>
- end if
- -- find which marker did we found.
- -- seems a bit redunant.
- set actualMarker to ""
- if (text foundMarkerOffset thru (foundMarkerOffset + 2) of theInputBuffer) is "<a " then
- set actualMarker to "<a "
- else if text foundMarkerOffset thru (foundMarkerOffset + 3) of theInputBuffer is "<img" then
- set actualMarker to "<img"
- else if text foundMarkerOffset thru (foundMarkerOffset + 6) of theInputBuffer is "http://" then
- set actualMarker to "http://"
- else if text foundMarkerOffset thru (foundMarkerOffset + 7) of theInputBuffer is "https://" then
- set actualMarker to "http://"
- else
- display dialog "Missed marker tag Found " & text foundMarkerOffset thru (foundMarkerOffset + 7) of theInputBuffer & " We will continue on, but no one knows how well." giving up after 10
- log " adjustURLs: ==> Missed marker tag. Found " & text foundMarkerOffset thru (foundMarkerOffset + 7) of theInputBuffer
- return theOriginalInputBuffer
- end if
- set actualMarkerOffsetLength to ((length of actualMarker) - 1)
- if debug ≥ 2 then
- log " adjustURLs: actualMarker is " & actualMarker & " actualMarkerOffsetLength is " & actualMarkerOffsetLength
- log " adjustURLs: foundMarkerOffset is " & getIntegerAndHex(foundMarkerOffset) & " verify marker text is " & text foundMarkerOffset thru (foundMarkerOffset + actualMarkerOffsetLength) of theInputBuffer
- end if
- if foundMarkerOffset ≥ 2 then
- -- collect and strip off characters that are before the marker.
- if debug ≥ 2 then
- log " adjustURLs: buildHTML is " & buildHtml & " length is " & getIntegerAndHex(length of buildHtml)
- hexDumpFormatOne(" adjustURLs: theInputBuffer", theInputBuffer)
- log " adjustURLs: (foundMarkerOffset - 1) is " & getIntegerAndHex((foundMarkerOffset - 1))
- end if
- -- get the proceding text
- set buildHtml to buildHtml & text 1 thru (foundMarkerOffset - 1) of theInputBuffer
- if debug ≥ 2 then
- log " adjustURLs: buildHTML is " & buildHtml
- hexDumpFormatOne(" adjustURLs: buildHTML", buildHtml)
- end if
- -- https://apple.stackexchange.com/a/20135/44531
- set theInputBuffer to text foundMarkerOffset thru -1 of theInputBuffer --trim off character before what we found
- if debug ≥ 2 then
- printHeader(" adjustURLs: theInputBuffer", theInputBuffer)
- hexDumpFormatOne(" adjustURLs: theInputBuffer", theInputBuffer)
- end if
- else
- log " adjustURLs: ==> no proceeding data."
- end if
- repeat 1 times -- interate loop
- -- example" the url is also the display text
- -- <a href="https://discussions.apple.com/docs/DOC-8841" target="_blank">https://discussions.apple.com/docs/DOC-8841</a>
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: theInputBuffer", theInputBuffer)
- -- check for the <a> tag
- if text 1 thru (length of "<a ") of theInputBuffer is "<a " then
- -- found <a> tag
- if debug ≥ 2 then log " adjustURLs: processing <a> tag"
- -- ASC consider a line-end as a <br> when when firefox considers it a blank
- -- change a possible line-end before an <a> tag to a " "
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: before lf check buildHTML", buildHtml)
- if text (length of buildHtml) thru (length of buildHtml) of buildHtml is lf then
- if debug ≥ 2 then log " adjustURLs: we need to delete a line-end before the <a> tag"
- set buildHtml to text 1 thru ((length of buildHtml) - 1) of buildHtml
- set buildHtml to buildHtml & " "
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: after lf deletion buildHTML", buildHtml)
- end if
- -- find ending </a> tag
- set whereEnds to offset of "</a>" in theInputBuffer
- if whereEnds ≤ 0 then
- if debug ≥ 2 then log " adjustURLs: ==> found an error in the HTML. no ending </a>"
- set buildHtml to buildHtml & theInputBuffer
- printHeader(" adjustURLs: buildHTML", buildHtml)
- set theInputBuffer to ""
- display dialog " adjustURLs: Found an error in the HTML. No ending </a>. Will skip." giving up after 10
- exit repeat -- ------ next ------>
- end if
- set lastOffsetLength to ((length of "</a>") - 1)
- if debug ≥ 2 then log " adjustURLs: lastOffsetLength is " & lastOffsetLength
- set lastCharacterOffset to whereEnds + lastOffsetLength
- if debug ≥ 2 then log " adjustURLs: lastCharacterOffset is " & getIntegerAndHex(lastCharacterOffset)
- -- needs to copy the ending ">"
- set anchorString to text 1 thru lastCharacterOffset of theInputBuffer
- -- don't let Windoze confuse us. convert Return LineFeed to lf
- -- Correct absure ASC bug where there is a line-end in the <a> text.
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: before adjusting anchorString", anchorString)
- set anchorString to alterString(anchorString, lf, " ")
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: anchorString", anchorString)
- set anchorString to adjustDuplicateAnchorURLs(anchorString, lf, " ")
- --
- -- fix up mangled url
- -- be a nice guy for RW -???-
- -- Waterfox fixes up!
- --
- set buildHtml to buildHtml & anchorString
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: buildHTML", buildHtml)
- -- https://apple.stackexchange.com/a/20135/44531
- -- We want first character of the "next" portion of theInputBuffer so add one
- set theInputBuffer to text (lastCharacterOffset + 1) thru -1 of theInputBuffer --trim out <a>
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: theInputBuffer", theInputBuffer)
- -- Web Browsers like Firefox convert a line-end in text to a space.
- if text 1 thru 1 of theInputBuffer is lf then
- if (length of theInputBuffer) is 1 then
- set theInputBuffer to " "
- else
- set theInputBuffer to " " & (text 2 thru (length of theInputBuffer) of theInputBuffer)
- if debug ≥ 2 then hexDumpFormatOne(" adjustURLs: after lf deletion; theInputBuffer", theInputBuffer)
- end if
- end if
- exit repeat -- ------ next ------>
- end if
- -- skip img tag which may contian a http or https.
- if text 1 thru (length of "<img") of theInputBuffer is "<img" then
- -- found <img> tag
- if debug ≥ 2 then log " adjustURLs: processing <img> tag"
- set {buildHtml, theInputBuffer} to skipTag(buildHtml, theInputBuffer, ">")
- exit repeat -- ------ next ------>
- end if
- set {theURL, theInputBuffer} to urlEndsWHere(theInputBuffer)
- if debug ≥ 2 then printHeader(" adjustURLs: printHeader", theInputBuffer)
- set actualTagData to getTitle(theURL)
- -- fyi: The string " _blank" in the <a> oOpens the linked document in a new window or tab.
- set assembled to "<a href=\"" & theURL & "\" target=\"_blank\">" & actualTagData & "</a>"
- if debug ≥ 2 then log " adjustURLs: assembled is " & assembled
- if (length of theInputBuffer) ≤ 0 then
- -- We have reached the end of the input
- if debug ≥ 2 then log " adjustURLs: we have reached the end of the input."
- set buildHtml to buildHtml & assembled
- else
- if debug ≥ 2 then log " adjustURLs: more input to process"
- set buildHtml to buildHtml & assembled
- end if
- -- wrap up
- --log "transformed text from buildHTML is " & return & buildHTML
- if debug ≥ 2 then log " adjustURLs: #" & countI & " transformed text from buildHTML is " & return & buildHtml
- -- number of links found
- set countI to countI + 1
- end repeat -- used to interate
- end repeat -- processing links in the input text
- if alteredBuffer is true then
- -- chop off the lf we added above.
- set buildHtml to text 1 thru ((length of buildHtml) - 1) of buildHtml
- set alteredBuffer to false -- somewhat redundant
- end if
- if debug ≥ 4 then log "bye from -.- adjustURLs -.-"
- return the buildHtml
- end adjustURLs
- -- ------------------------------------------------------
- (*
- alterString
- thisText is the input string to change
- delim is what string to change. It doesn't have to be a single character.
- replacement is the new string
- returns the changed string.
- *)
- on alterString(thisText, delim, replacement)
- global debug
- if debug ≥ 5 then log "in ~~~ alterString ~~~"
- set resultList to {}
- set {tid, my text item delimiters} to {my text item delimiters, delim}
- try
- set resultList to every text item of thisText
- set text item delimiters to replacement
- set resultString to resultList as string
- set my text item delimiters to tid
- on error
- set my text item delimiters to tid
- end try
- return resultString
- end alterString
- -- ------------------------------------------------------
- (*
- Return the text to the right of theToken.
- *)
- on answerAndChomp(theString, theToken)
- global debug
- if debug ≥ 5 then log "in ~~~ answerAndChomp ~~~"
- set theOffset to offset of theToken in theString
- if debug ≥ 7 then log "theOffset is " & theOffset
- set theLength to length of theString
- if theOffset > 0 then
- set beginningPart to text 1 thru (theOffset - 1) of theString
- if debug ≥ 7 then log "beginningPart is " & beginningPart
- set chompped to text theOffset thru theLength of theString
- if debug ≥ 7 then log "chompped is " & chompped
- return {chompped, beginningPart}
- else
- set beginningPart to ""
- return {theString, beginningPart}
- end if
- end answerAndChomp
- -- ------------------------------------------------------
- (*
- Delete the leading part of the string until and including theToken.
- *)
- on chompLeftAndTag(theString, theToken)
- global debug
- if debug ≥ 5 then log "in --- chompLeftAndTag ---"
- if debug ≥ 7 then
- log "chompLeftAndTag: theToken is " & theToken
- hexDumpFormatOne("chompLeftAndTag: theString", theString)
- end if
- set theOffset to offset of theToken in theString
- if debug ≥ 7 then log "chompLeftAndTag: theOffset is " & theOffset & " in hex is " & integerToHex(theOffset)
- set theLength to length of theString
- if debug ≥ 7 then log "chompLeftAndTag: theLength is " & theLength & " in hex is " & integerToHex(theLength)
- if theOffset > 0 then
- -- Do we have any more of the string to return?
- if (theOffset + (length of theToken)) ≤ length of theString then
- set chompped to text (theOffset + (length of theToken)) thru theLength of theString
- else
- set chompped to ""
- end if
- if debug ≥ 7 then log "chompLeftAndTag: length of chompped is " & integerToHex(length of chompped) & "; chompped is " & chompped
- return chompped
- else
- return ""
- end if
- end chompLeftAndTag
- -- ------------------------------------------------------
- on convertToHTML(theData)
- global debug
- if debug ≥ 3 then log "in --- convertToHTML ---" & return & " Try to send back HTML. the processed data in variable theData is " & theData
- try
- set clipboardDataQuoted to quoted form of theData
- if debug ≥ 1 then
- log " convertToHTMLz: .... data soon to be returned ...." & return & "clipboardDataQuoted is " & return & clipboardDataQuoted
- hexDumpFormatOne("clipboardDataQuoted", clipboardDataQuoted)
- end if
- -- make hex string as required for HTML data on the clipboard
- set toUnix to "/bin/echo -n " & clipboardDataQuoted & " | hexdump -ve '1/1 \"%.2x\"'"
- if debug ≥ 5 then printHeader(" convertToHTMLz: toUnix to convert to hex", toUnix)
- set fromUnix to do shell script toUnix
- if debug ≥ 5 then printHeader(" convertToHTMLz: fromUnix", fromUnix)
- if debug ≥ 5 then
- log " convertToHTMLz: displaying original string -- so we can tell if it converted successfully. "
- --hexDumpFormatOne("fromUnix", fromUnix)
- end if
- on error errMsg number n
- log " convertToHTMLz: ==> convert to hex string failed. " & errMsg & " with number " & n
- set fromUnix to ""
- end try
- if debug ≥ 4 then log "bye from -.- convertToHTML -.-"
- return fromUnix
- end convertToHTML
- -- ------------------------------------------------------
- (*
- Yvan Koenig
- https://macscripter.net/viewtopic.php?id=43133
- *)
- on findExtension(inputFileName)
- global debug
- if debug ≥ 5 then log "in ~~~ findExtension ~~~"
- set fileName to inputFileName as string
- set saveTID to AppleScript's text item delimiters
- set AppleScript's text item delimiters to {"."}
- set theExt to last text item of fileName
- set AppleScript's text item delimiters to saveTID
- --log "theExt is " & theExt
- if theExt ends with ":" then set theExt to text 1 thru -2 of theExt
- if debug ≥ 5 then log "theExt is " & theExt
- return theExt
- end findExtension
- -- ------------------------------------------------------
- (*
- length of inputLfBuffer & " in hex " & integerToHex(length of inputLfBuffer)
- *)
- on getIntegerAndHex(aNumber)
- global debug
- if debug ≥ 5 then log "in ~~~ getIntegerAndHex ~~~"
- return aNumber & " in Hex " & integerToHex(aNumber)
- end getIntegerAndHex
- -- ------------------------------------------------------
- (*
- find the html title in the given web page.
- retrieve the file pointed to by the URL so we can
- get the title. Note: <title> can have attributes. Example:
- <title data-test-page-title="Parallels Desktop Lite on the Mac App Store"
- >Parallels Desktop Lite on the Mac App Store</title>
- *)
- on getTitle(theURL)
- global debug
- global droppedFileName
- set lf to character id 10
- if debug ≥ 5 then log "in ~~~ getTitle ~~~"
- if debug ≥ 1 then log " getTitle: ----------------------- " & theURL & " -----------------------"
- if (text 1 thru (length of "http:") of theURL is "http:") or (text 1 thru (length of "https:") of theURL is "https:") then
- -- found url we can process
- if debug ≥ 5 then log "getTitle: We can process this URL since it begins with http or https." & return & " " & theURL
- else
- log "==> getTitle: we cannot process this url " & theURL & return & " we will return what we received."
- return theURL --------------------------------->
- end if
- -- Example:
- -- curl --silent --location --max-time 10 <URL>
- set toUnix to "curl --silent --location --max-time 10 " & quoted form of theURL
- if debug ≥ 2 then log " getTitle: what we will use to retrieve the Url. toUnix is " & return & " " & toUnix
- try
- if debug ≥ 2 then log " getTitle: reading link file to get title"
- set fromUnix to do shell script toUnix
- -- enough data returned to have a title in it?
- if debug ≥ 2 then
- log " getTitle: (length of fromUnix) is " & (length of fromUnix)
- log " getTitle: length of (\"<title" & "</title>\")) is " & (length of ("<title" & "</title>"))
- end if
- if (length of fromUnix) < (length of ("<title" & "</title>")) then
- log "==> getTitle: site didn't return any data " & theURL & return & " we will return what ee received."
- return theURL --------------------------------->
- end if
- if debug ≥ 2 then
- printHeader(" getTitle: fromUnix", fromUnix)
- -- may not be working with an HTLM document, so thefound title may be too long or confused.
- log " getTitle: how far?..."
- end if
- -- there could be some bagage with the <title
- set actualTagData to tagContent(fromUnix, "<title", "</title>")
- -- Find what we will actually display in the title.
- -- Fix up gotchas.
- if debug ≥ 2 then
- log " getTitle: actualTagData is ->" & actualTagData & "<-"
- hexDumpFormatOne(" getTitle: actualTagData (title)", actualTagData)
- end if
- if actualTagData is "" then
- set actualTagData to theURL
- else if length of actualTagData > 140 then
- if debug ≥ 2 then log " getTitle: length of actualTagData is " & length of actualTagData & "which is too long. Truncated."
- set actualTagData to theURL
- -- curl https://appleid.apple.com returns <title>403 Forbidden</title>
- -- which is misleading.
- -- will be extraneous characters in the title now since we haven't yet filtered them out.
- else if actualTagData contains "403" and actualTagData contains "Forbidden" then
- if debug ≥ 2 then log " getTitle: found 403 web page."
- set actualTagData to theURL
- -- <title>Sign In - Apple</title>
- -- got a post from the lounge.
- else if actualTagData contains "Sign In - Apple" then
- if debug ≥ 2 then log " getTitle: got 'Sign In - Apple' from a lounge page."
- set actualTagData to theURL
- else
- -- there could be some attributes within the <title> tag.
- -- or there could not be
- -- could an attribute have a > in it? doubtful. should be escaped.
- try
- if debug ≥ 2 then log " getTitle: looks like a normalist title."
- -- find where <title ends
- set whereToEnd to (offset of ">" in actualTagData)
- if debug ≥ 2 then log " getTitle: whereToEnd is " & whereToEnd
- set whereToBegin to whereToEnd + (length of ">")
- if debug ≥ 2 then
- log " getTitle: whereToBegin is " & whereToBegin
- hexDumpFormatOne(" getTitle: actualTagData", actualTagData)
- end if
- set actualTagData to text whereToBegin thru (length of actualTagData) of actualTagData
- if debug ≥ 2 then log " getTitle: actualTagData is " & actualTagData
- on error theErrorMessage number theErrorNumber
- log " getTitle: ==>No ending greater than (>) for title. Badly contructed html." & return & "message is " & theErrorMessage & "error number " & theErrorNumber
- set actualTagData to actualTagData
- -- no need to repair. It's not our page.
- end try
- -- found line-end in title. caused confustion.
- -- note: this is new data and the multiple line-ends have not been
- -- filtered out.
- -- some joker had a line-end in the title!
- if debug ≥ 3 then
- log " getTitle: actualTagData (title) has been chanaged which is " & actualTagData
- hexDumpFormatOne(" getTitle: actualTagData (title)", actualTagData)
- end if
- set actualTagData to alterString(actualTagData, return & lf, lf)
- set actualTagData to alterString(actualTagData, return, lf)
- set actualTagData to adjustLF(actualTagData)
- if debug ≥ 2 then
- log " getTitle: actualTagData (title) has been chanaged which is " & actualTagData
- hexDumpFormatOne(" getTitle: actualTagData (title)", actualTagData)
- end if
- end if
- on error errMsg number n
- display dialog " getTitle: ==> Error occured when looking for title. " & errMsg & " with number " & n & return & " " & droppedFileName & return & " " & theURL giving up after 10
- log " getTitle: ==> Error occured when looking for title. " & errMsg & " with number " & n
- set actualTagData to theURL
- end try
- return actualTagData
- end getTitle
- -- ------------------------------------------------------
- (*
- http://krypted.com/mac-os-x/to-hex-and-back/
- 0 2 4 6 8 a c e 0 2 4 6 8 a c e
- 0000000: 3c 703e 5369 6d70 6c65 2070 7574 2c20 <p>Simple put,
- *)
- on hexDumpFormatOne(textMessage, hex)
- global debug
- set aNul to character id 1
- if debug ≥ 7 then log "in ~~~ hexDumpFormatOne ~~~"
- if debug ≥ 8 then log " hexDumpFormatOne: input string is " & return & hex
- -- -r -p
- set displayValue to aNul & hex
- set toUnix to "/bin/echo -n " & (quoted form of displayValue) & " | xxd "
- if debug ≥ 8 then log " hexDumpFormatOne: toUnix is " & toUnix
- try
- set fromUnix to do shell script toUnix
- -- two hex digits
- set displayText to replaceCharacter(fromUnix, 10, " ")
- if debug ≥ 8 then
- log " hexDumpFormatOne: " & return & displayText
- log " hexDumpFormatOne: length of displayText is " & length of displayText
- end if
- -- one character
- set displayText to replaceCharacter(displayText, 51, " ")
- if debug ≥ 8 then
- log " hexDumpFormatOne: " & return & displayText
- log " hexDumpFormatOne: almost there ..... length of displayText is " & length of displayText
- end if
- 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
- on error errMsg number n
- log " hexDumpFormatOne: ==> convert hex string to string failed. " & errMsg & " with number " & n
- end try
- if debug ≥ 8 then
- log "leaving ~.~ hexDumpFormatOne ~.~"
- end if
- end hexDumpFormatOne
- -- ------------------------------------------------------
- on hexDumpFormatZero(textMessage, hex)
- global debug
- if debug ≥ 7 then log "in ~~~ hexDumpFormatZero ~~~"
- if debug ≥ 8 then log "input string is " & hex
- -- -r -p
- set toUnix to "/bin/echo -n " & (quoted form of hex) & " | xxd "
- if debug ≥ 8 then log "toUnix is " & toUnix
- try
- set displayText to do shell script toUnix
- 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
- on error errMsg number n
- log "==> convert hex string to string failed. " & errMsg & " with number " & n
- end try
- end hexDumpFormatZero
- -- ------------------------------------------------------
- (*
- https://macscripter.net/viewtopic.php?id=43713
- *)
- on integerToHex(nDec)
- global debug
- if debug ≥ 5 then log "in ~~~ integerToHex ~~~"
- try
- set nHex to do shell script "perl -e 'printf(\"%X\", " & nDec & ")'" --> "F0"
- on error errMsg number n
- log "==> convert integer to hex. " & errMsg & " with number " & n
- set nHex to ""
- end try
- return nHex
- end integerToHex
- -- ------------------------------------------------------
- (*
- https://stackoverflow.com/questions/55838252/minimum-value-that-not-zero
- set m to get minimumPositiveNumber from {10, 2, 0, 2, 4}
- log "m is " & m
- set m to minimumPositiveNumber from {0, 0, 0}
- log "m is " & m
- *)
- on minimumPositiveNumber from L
- global debug
- if debug ≥ 5 then log "in ~~~ minimumPositiveNumber ~~~"
- local L
- if L = {} then return null
- set |ξ| to 0
- repeat with x in L
- set x to x's contents
- if (x < |ξ| and x ≠ 0) ¬
- or |ξ| = 0 then ¬
- set |ξ| to x
- end repeat
- |ξ|
- end minimumPositiveNumber
- -- ------------------------------------------------------
- (*
- makeCaseUpper("Now is the time, perhaps, for all good men")
- *)
- on makeCaseUpper(theString)
- global debug
- if debug ≥ 5 then log "in ~~~ makeCaseUpper ~~~"
- set UC to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- set LC to "abcdefghijklmnopqrstuvwxyz"
- set C to characters of theString
- repeat with ch in C
- if ch is in LC then set contents of ch to item (offset of ch in LC) of UC
- end repeat
- return C as string
- end makeCaseUpper
- -- ------------------------------------------------------
- on postToCLipboard(pleasePost)
- global debug
- if debug ≥ 5 then log "in ~~~ postToCLipboard ~~~"
- try
- -- osascript -e "set the clipboard to «data HTML${hex}»"
- set toUnixSet to "osascript -e \"set the clipboard to «data HTML" & pleasePost & "»\""
- if debug ≥ 5 then log " postToCLipboard: toUnixSet is " & printHeader("toUnixSet", toUnixSet)
- set fromUnixSet to do shell script toUnixSet
- if debug ≥ 5 then log " postToCLipboard: fromUnixSet is " & fromUnixSet
- on error errMsg number n
- log " postToCLipboard: ==> We tried to send back HTML data, but failed. " & errMsg & " with number " & n
- end try
- -- see what ended up on the clipboard
- set theList2 to clipboard info
- if debug ≥ 2 then printClipboardInfo(theList2)
- end postToCLipboard
- -- ------------------------------------------------------
- on printClipboardInfo(theList)
- global debug
- if debug ≥ 5 then log "in ~~~ printClipboardInfo ~~~"
- log (clipboard info)
- log class of theList
- log "Data types on the clipboard ... "
- printList("", theList)
- log "... "
- end printClipboardInfo
- -- ------------------------------------------------------
- (* Pump out the beginning of theString *)
- on printHeader(theName, theString)
- global debug
- if debug ≥ 7 then
- log "in ~~~ printHeader ~~~"
- log " printHeader: the input string for titling is " & theName
- -- let's not culter the log
- log " printHeader: length of the string to print is " & length of theString
- end if
- if length of theString ≤ 0 then
- log "==> no string to print"
- else
- log theName & " is " & return & text 1 thru (minimumPositiveNumber from {400, length of theString}) of theString & "<+++++++++"
- end if
- end printHeader
- -- ------------------------------------------------------
- (*
- print out the items in a list
- *)
- on printList(theName, splits)
- global debug
- if debug ≥ 5 then log "in ~~~ printList ~~~"
- try
- set theCount to 1
- repeat with theEntry in splits
- if debug ≥ 7 then log "printList: class of theEntry is " & class of theEntry
- set classDisplay to class of theEntry as text
- if debug ≥ 7 then "printList: classDisplay is " & classDisplay as text
- if debug ≥ 7 then log "printList: class of classDisplay is " & class of classDisplay
- if classDisplay is "list" then
- log " " & theName & " # " & theCount & " is " & item 1 of theEntry & "; " & item 2 of theEntry
- else
- log " " & theName & " # " & theCount & " is " & theEntry
- end if
- set theCount to theCount + 1
- end repeat
- on error errMsg number n
- log "printList: ==> No go in printList. " & errMsg & " with number " & n
- end try
- end printList
- -- ------------------------------------------------------
- (*
- StefanK in https://macscripter.net/viewtopic.php?id=43852
- Replaces one or more characters based on the length of theCharacter.
- Big Warning!!!
- ==============
- This on block is called by hexDumpFormatOne().
- Therefor, you may not call hexDumpFormatOne() from this on block.
- If you so so, you get yourself into an endless loop.
- Use hexDumpFormatZero() instead.
- script -k <output file name>
- osascript /Applications/applescriptFiles/workwithclipboardV13-HTML.app
- use Activity Monito to stop osascript
- *)
- on replaceCharacter(theText, theOffset, theCharacter)
- global debug
- if debug ≥ 7 then log "in ~~~ replaceCharacter ~~~"
- if debug ≥ 7 then
- log " theOffset is " & getIntegerAndHex(theOffset) & " with theCharacter >" & theCharacter & "< length of theText is " & getIntegerAndHex(length of theText)
- log "theText is " & theText
- end if
- set theOutput to theText -- ready to return if need be.
- repeat 1 times
- -- sanity checks
- if theOffset ≤ 0 then
- display dialog "No character to replace at " & theOffset & " with character " & theCharacter & " in " & theText giving up after 10
- log "==> Adjust theOffset to be wihin the string."
- exit repeat -------------- return ---------->
- end if
- if (theOffset - (length of theCharacter)) ≤ 0 then
- display dialog "Too near the front of the buffer. " & theOffset & " with character " & theCharacter & " in " & theText giving up after 10
- log "==> Too near the front of the buffer. "
- exit repeat -------------- return ---------->
- end if
- if (theOffset + (length of theCharacter) - 1) > (length of theText) then
- display dialog "To near the end of the buffer. " & theOffset & " with character " & theCharacter & " in " & theText giving up after 10
- log "==> Too near the end of the buffer. "
- log " " & "theOffset is " & theOffset & " with theCharacter >" & theCharacter & "< in " & theText
- log "length of buffer is " & getIntegerAndHex(length of theText)
- exit repeat -------------- return ---------->
- end if
- if debug ≥ 7 then
- log "theOffset is " & getIntegerAndHex(theOffset)
- log "theCharacter is " & theCharacter
- end if
- try
- -- what if we are at the end of the buffer. We cannot get any remainder text.
- if theOffset ≥ (length of theText) then
- set theOutput to (text 1 thru (theOffset - 1) of theText) & theCharacter
- else
- set theOutput to (text 1 thru (theOffset - 1) of theText) & theCharacter & (text (theOffset + (length of theCharacter)) thru -1 of theText)
- end if
- on error errMsg number n
- log "==> No go. " & errMsg & " with number " & n
- exit repeat -------------- return ---------->
- end try
- end repeat
- return theOutput
- end replaceCharacter
- -- ------------------------------------------------------
- (*
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- DOCTYPE contains a http link, but it's not something we want to mess with.
- Tip: The <!DOCTYPE> declaration is NOT case sensitive.
- https://www.w3schools.com/tags/tag_doctype.asp
- best do the parsing maually, since we will not know the casing of DOCTYPE.
- fyi: An HTML comment begins with <!–– and the comment closes with ––> .
- *)
- on skipDoctype(buildHtml, theInputBuffer)
- global debug
- if debug ≥ 5 then log "in --- skipDoctype ---"
- set ourOutput to buildHtml
- set ourInput to theInputBuffer
- set splitDoctype to splitTextToList(ourInput, "<!")
- if (count of splitDoctype) ≤ 1 then
- if debug ≥ 4 then log "skipDoctype: <! hence DOCTYPE not found."
- return {buildHtml, theInputBuffer} ------------------ <! not found -------------------->
- end if
- set firstWordOffset to offset of " " in (item 2 of splitDoctype)
- -- ditch trailing blank.
- set firstWordOffset to firstWordOffset - 1
- if firstWordOffset ≤ 0 then
- if debug ≥ 4 then log "skipDoctype: DOCTYPE not found."
- return {buildHtml, theInputBuffer} ------------------ <! not found -------------------->
- end if
- -- it was simple to get the header stuff at least
- set ourOutput to ourOutput & item 1 of splitDoctype
- set firstWord to makeCaseUpper(text 1 thru firstWordOffset of (item 2 of splitDoctype))
- if debug ≥ 4 then log "skipDoctype: firstWord is " & firstWord & " length of firstWord is " & length of firstWord & " class of firstWord is " & class of firstWord
- if firstWord is "<!DOCTYPE" then
- -- skip over DOCTYPE tag.
- set endOfDoctypeOffset to offset of ">" in (item 2 of splitDoctype)
- if endOfDoctypeOffset ≤ 0 then
- if debug ≥ 5 then log "skipDoctype: Closing " > " not found with DOCTYPE."
- return {buildHtml, theInputBuffer} ------------------ ">" not found ---------------->
- end if
- -- looks good. proceed.
- set ourOutput to ourOutput & text 1 thru endOfDoctypeOffset of (item 2 of splitDoctype)
- set ourInput to text ((length of (item 1 of splitDoctype)) + endOfDoctypeOffset + 1) thru -1 of theInputBuffer
- else
- if debug ≥ 4 then log "skipDoctype: DOCTYPE not found as first word."
- return {buildHtml, theInputBuffer} ---------- DOCTYPE not found ---------->
- end if
- if debug ≥ 4 then log "skipDoctype:" & return & "ourOutput, is " & ourOutput & return & "ourInput, is " & ourInput
- return {ourOutput, ourInput}
- end skipDoctype
- -- ------------------------------------------------------
- on skipTag(buildHtml, theInputBuffer, endDelim)
- global debug
- if debug ≥ 5 then log "in --- skipTag ---"
- set theOutput to buildHtml
- set theInput to theInputBuffer
- if debug ≥ 4 then
- log "skipTag: length of theOutput is " & (length of theOutput) & " length of theInput is " & (length of theInput)
- log "skipTag: endDelim is ->" & endDelim & "<-"
- end if
- set endOfTagOffset to offset of endDelim in theInput
- -- did we find the end tag?
- if endOfTagOffset ≤ 0 then
- try
- display dialog "skipTag: tag not balanced. beginning tag is" & text 1 thru 4 of theInput & " ending tag is " & endDelim giving up after 10
- log "skipTag: ==> tag not balanced. beginning tag is" & text 1 thru 4 of theInput & " ending tag is " & endDelim
- on error errMsg number n
- log "skipTag: ==> tag not balanced." & errMsg & " with number " & n
- display dialog "skipTag: tag not balanced." giving up after 10
- end try
- -- no end tag, so consider the rest as consumed
- set theOutput to ourOutput & theInput
- set theInput to ""
- return {theOutput, theInput} -- ------------------------------------------->
- end if
- -- looks good. proceed.
- set theOutput to theOutput & text 1 thru endOfTagOffset of theInput
- if endOfTagOffset < (length of theInput) then
- -- loob off tag
- set theInput to text (endOfTagOffset + 1) thru -1 of theInput
- else
- set theInput to ""
- end if
- if debug ≥ 4 then
- log "skipTag: length of theOutput is " & (length of theOutput) & " length of theInput is " & (length of theInput)
- printHeader("skipTag: theOutput", theOutput)
- printHeader("skipTag: theInput", theInput)
- end if
- return {theOutput, theInput}
- end skipTag
- -- ------------------------------------------------------
- (*
- splitTextToList seems to be what you are trying to do
- thisText is the input string
- delim is what to split on
- results returned in a list
- Total hack. We know splitTextToList strips of delim so add it back.
- *)
- on splitTextToList(thisText, delim)
- global debug
- if debug ≥ 5 then log "in ~~~ splitTextToList ~~~"
- set returnedList to textToList(thisText, delim)
- set resultArray to {}
- copy item 1 of returnedList to the end of the resultArray
- repeat with i from 2 to (count of returnedList) in returnedList
- set newElement to delim & item i of returnedList
- copy newElement to the end of the resultArray
- end repeat
- return resultArray
- end splitTextToList
- -- ------------------------------------------------------
- (*
- Retrieved data between "begin" and "end" tag. Whatever is between the strings.
- *)
- on tagContent(theString, startTag, endTag)
- global debug
- if debug ≥ 5 then log "in ~~~ tagContent ~~~"
- try
- if debug ≥ 5 then log "tagContent: " & return & " startTag is ->" & startTag & "<- endTag is ->" & endTag & "<-"
- set beginningOfTag to chompLeftAndTag(theString, startTag)
- if length of beginningOfTag ≤ 0 then
- set middleText to ""
- else
- if debug ≥ 5 then printHeader("tabContent: beginningOfTag", beginningOfTag)
- set endingOffset to (offset of endTag in beginningOfTag)
- if endingOffset ≤ (length of endTag) then
- set middleText to ""
- else
- set middleText to text 1 thru (endingOffset - 1) of beginningOfTag
- if debug ≥ 5 then printHeader("tabContent: middleText", middleText)
- end if
- end if
- on error errMsg number n
- log "tagContent: ==> finding contained text failed. " & errMsg & " with number " & n
- set middleText to ""
- end try
- if debug ≥ 5 then log "tagContent: returning with middleText is " & middleText
- return middleText
- end tagContent
- -- ------------------------------------------------------
- (*
- textToList seems to be what you are trying to do
- thisText is the input string
- delim is what to split on
- returns a list of strings.
- - textToList was found here:
- - http://macscripter.net/viewtopic.php?id=15423
- *)
- on textToList(thisText, delim)
- global debug
- if debug ≥ 5 then log "in ~~~ textToList ~~~"
- set resultList to {}
- set {tid, my text item delimiters} to {my text item delimiters, delim}
- try
- set resultList to every text item of thisText
- set my text item delimiters to tid
- on error
- set my text item delimiters to tid
- end try
- return resultList
- end textToList
- -- ------------------------------------------------------
- on trimCharacters(inputTrim, outputTrim, reduce)
- global debug
- if debug ≥ 5 then log "in ~~~ trimCharacters ~~~"
- if debug ≥ 6 then
- log " trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
- hexDumpFormatOne(" trimCharacters: inputTrim", inputTrim)
- log " trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
- hexDumpFormatOne(" trimCharacters: outputTrim", outputTrim)
- log " trimCharacters: with reduce >" & reduce & "< "
- end if
- set repCount to 1
- repeat while length of inputTrim ≥ 1 and text 1 thru 1 of inputTrim is " "
- set {inputTrim, outputTrim} to trimOneChar(inputTrim, outputTrim, 1, "")
- if debug ≥ 6 then
- log " trimCharacters: repCount is " & repCount
- set repCount to repCount + 1
- log " trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
- hexDumpFormatOne(" trimCharacters: cycling inputTrim", inputTrim)
- log " trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
- hexDumpFormatOne(" trimCharacters: cycling outputTrim", outputTrim)
- end if
- end repeat
- if debug ≥ 6 then
- log " trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
- hexDumpFormatOne(" trimCharacters: completed inputTrim", inputTrim)
- log " trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
- hexDumpFormatOne(" trimCharacters: completed outputTrim", outputTrim)
- log "bye from ~.~ trimCharacters ~.~"
- end if
- return {inputTrim, outputTrim}
- end trimCharacters
- -- ------------------------------------------------------
- on trimOneChar(inputLf, outputTrimmed, theLfOffset, substitueCharacter)
- global debug
- if debug ≥ 3 then
- log "in ~~~ trimOneChar ~~~"
- hexDumpFormatOne("inputLf", inputLf)
- hexDumpFormatOne("outputTrimmed", outputTrimmed)
- log "trimOneChar: theLfOffset, is " & getIntegerAndHex(theLfOffset)
- log "trimOneChar: with substitueCharacter >" & substitueCharacter & "< "
- end if
- -- check boundaries
- if theLfOffset ≤ 0 or (theLfOffset > (length of inputLf)) then
- -- We are almost done.
- if debug ≥ 3 then log "trimOneChar: no LF found."
- -- tack on any trialing stuff
- set outputTrimmed to outputTrimmed & inputLf
- set inputLf to ""
- if debug ≥ 3 then
- hexDumpFormatOne("trimOneChar: inputLf", inputLf)
- hexDumpFormatOne("trimOneChar: outputTrimmed", outputTrimmed)
- end if
- return {inputLf, outputTrimmed} ------------ return ------------>
- end if
- -- We need to deal with output first, so we haven't trimmed the input we need.
- if theLfOffset ≥ 2 then
- if debug ≥ 6 then log " theLfOffset ≥ 2"
- set outputTrimmed to outputTrimmed & (text 1 thru (theLfOffset - 1) of inputLf) & substitueCharacter
- else if theLfOffset = 1 then
- if debug ≥ 6 then log " theLfOffset = 1"
- -- no stuff before the lf
- set outputTrimmed to outputTrimmed & substitueCharacter
- end if
- -- deal with inputLf.
- if theLfOffset < (length of inputLf) then
- if debug ≥ 6 then log "trimOneChar: theLfOffset < (length of inputLf) "
- -- trailing stuff
- set inputLf to text (theLfOffset + 1) thru -1 of inputLf
- else if theLfOffset is (length of inputLf) then
- if debug ≥ 6 then log "trimOneChar: theLfOffset is (length of inputLf) "
- set inputLf to ""
- end if
- if debug ≥ 3 then
- hexDumpFormatOne("trimOneChar: inputLf", inputLf)
- hexDumpFormatOne("trimOneChar: outputTrimmed", outputTrimmed)
- end if
- if debug ≥ 4 then log "bye from ~.~ trimOneChar ~.~"
- return {inputLf, outputTrimmed}
- end trimOneChar
- -- ------------------------------------------------------
- (*
- Unix-like systems LF 0A \n
- (Linux, macOS)
- Microsoft Windows CRLF 0D 0A \r\n
- classic Mac OS CR 0D \r Applescript return
- *)
- on typeText(theData)
- global debug
- if debug ≥ 5 then log "in ~~~ typeText ~~~"
- set lf to character id 1
- if debug ≥ 2 then printHeader("the input ( theData )", theData)
- -- Example: -- https://discussions.apple.com/docs/DOC-8841
- -- locate links
- set theOutputBuffer to adjustURLs(theData, {"https://", "http://", "<a ", "<img"})
- -- add paragraphs
- set theOutputBuffer to addParagraphs(theOutputBuffer)
- if debug ≥ 2 then log "theOutputBuffer is " & return & theOutputBuffer
- if debug ≥ 4 then log "bye from -.- typeText -.-"
- return theOutputBuffer
- end typeText
- -- ------------------------------------------------------
- (*
- find the end of an URL
- -- find the end of the HTML URL by splitting on blank or return
- -- unsafe characters <blank> " < > # % { } | \ ^ ~ [ ] `
- -- and line-end
- -- while # is listed as unsafe, it does appear in a url as a marker of some sort.
- -- leave it out as an ending character.
- -- https://perishablepress.com/stop-using-unsafe-characters-in-urls/
- -- the end of the clipboard string my end after the url, hence no " ", LF or CR
- -- Rember, CRLF was converted to LF above
- *)
- on urlEndsWHere(theInputBuffer)
- global debug
- set lf to character id 10
- if debug ≥ 5 then log "in ~~~ urlEndsWHere ~~~"
- set endsWhere to {}
- -- the end of the url ends with one of the not allowed characters + line-end
- repeat with unsafeCharacter in {" ", "\"", lf, "<", ">", "%", "{", "}", "|", "\\", "^", "~", "[", "]"}
- copy (offset of unsafeCharacter in theInputBuffer) to the end of the endsWhere
- end repeat
- if debug ≥ 6 then log endsWhere
- set endOfURL to (minimumPositiveNumber from endsWhere) - 1
- if debug ≥ 6 then log " urlEndsWHere: endOfURL is " & endOfURL
- if endOfURL ≤ 0 then
- -- We have reached the end of the input
- set theURL to theInputBuffer
- set theInputBuffer to ""
- else
- set theURL to text 1 thru endOfURL of theInputBuffer
- if debug ≥ 6 then log " urlEndsWHere:s: from middle theURL is " & theURL
- set theInputBuffer to text (endOfURL + 1) thru -1 of theInputBuffer -- trim off url in front.
- end if
- return {theURL, theInputBuffer}
- end urlEndsWHere
- -- ------------------------------------------------------
- (*
- place debuging data on cipboard
- has a big side effect.
- *)
- on wrapupClipboardDataSelector()
- global debug
- if debug ≥ 5 then log "in ~~~ wrapupClipboardDataSelector ~~~"
- return "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
- <title>roger's troubles.html</title></head>
- <body>There are apps in the Play Store to sync calendars and contacts -
- search on
- Smoothsync for two of the best. <br>
- <br>
- iCloud mail is standard IMAP and you
- can access it in the mail application using the settings here:<br>
- <br>
- <a href=\"https://support.apple.com/HT202304\">https://support.apple.com/HT202304</a><br>
- <br>
- 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.<br>
- <br>
- <a href=\"https://support.apple.com/HT204915\">https://support.apple.com/HT204915</a><br>
- <br>
- <a href=\"https://support.apple.com/HT204397\">https://support.apple.com/HT204397</a><br>
- <br>
- If you are unable to set up two-factor authentication you should set up
- 2-step verification and use that to create an app-specific password
- (see link below) . Then go
- to <a href=\"https://appleid.apple.com\">https://appleid.apple.com </a>, select 'Password and Security'; click
- 'Generate an App-Specific
- Password' and follow the instructions. Once you have the password, copy
- it and paste it into the password field in the application instead of
- your usual iCloud password. You should also keep a note of it (though
- you can generate a new one if required).<br>
- <br>
- <a href=\"https://support.apple.com/kb/HT204152\">https://support.apple.com/kb/HT204152</a><br>
- <br>
- You will need to nominate a 'trusted device' - any phone capable of
- receiving SMS messages. There will be a 2-day wait before you can
- complete the process.<br>
- (A particular caveat (about 2-step only) - you will be issued with a
- 'Recovery Key' in case you lose your 'trusted device'. Make sure to
- write this down and keep it in a safe place; if you lose both it and
- your trusted device you will be permanently locked out of your ID.
- You'd be surprised at the number of people who've posted here that
- they've got themselves into just that position.)</body></html>"
- end wrapupClipboardDataSelector
- (* <br>
- Strictly speaking all purchases
- are final (after all, you can't very well return them): please see this
- page for information on requesting a refund:<a href=\"https://support.apple.com/HT204084\"> https://support.apple.com/HT204084</a><br>
- <br>However Apple have been known to be sympathetic in cases of
- actual error, so it's possible that they may allow you a refund as a
- one-off concession: but please be aware that they are under no
- 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>
- <br style=\"font-family: Arial;\">
- <span style=\"font-family: Arial;\">Alternatively go to the page
- 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\">
- </a><br>
- *)
- (* return "<html><head>
- <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
- <title>asc insert title in <a>.html</title>
- </head>
- <body>
- <p></p>
- <p>\"Avoid phishing scams\"
- <a href=\"https://support.apple.com/en-ca/HT204759\">https://support.apple.com/en-ca/HT204759</a>
- </p>
- <p>Lets pad the <a> tag.</p>
- <p>
- <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>
- </p>
- <p>That's all folks.</p><p></p>
- </body>
- <html>"
- *)
- (*
- "Global Lyme Alliance Reveals Several Drugs and Drug Combinations That Show Success in Treating Lyme Disease
- 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
- https://www.omf.ngo/community-symposium-2/
- Saturday, September 7, 2019
- Live streamed
- https://www.omf.ngo/community-symposium-2/
- New OMF-funded Research Publication: A Nanoelectronics-blood-based diagnostic biomarker for ME/CFS
- Dr. Ron Davis, OMF Scientific Advisory Board Director, explains the PNAS publication on the nanoneedle (April 29, 2019)
- 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.
- https://www.youtube.com/watch?v=6Qn0fIV8SbE&feature=youtu.be"
- return "<p> </p><p> </p><p>If you are unable to set up \"two-factor authentication,\" you should set up \"2-step.\"
- Run etrecheck. The
- first five runs are free.</p> "
- *)
- (*
- 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.\"
- Run etrecheck. The
- first five runs are free. Provided a report on your
- machines hardware and software. Great for diagnosing your system. Click on the download
- link at the bottom of the screen.
- <a href=\"http://etrecheck.com/\" target=\"_blank\">EtreCheck</a></p><p></p>
- <p></p><p>
- <ol>
- <li>point 1</li>
- <li>point 2</li>
- <li>point 3</li>
- </ol>
- </p>
- <p>the end</p>
- </ol></p><p>
- "
- *)
- (*
- https://www.oreilly.com/library/view/applescript-the-definitive/0596102119/re89.html
- https://stackoverflow.com/questions/11085654/apple-script-how-can-i-copy-html-content-to-the-clipboard
- -- user has copied a file's icon in the Finder
- clipboard info
- -- {{string, 20}, {«class ut16», 44}, {«class hfs », 80}, {«class
- utf8», 20}, {Unicode text, 42}, {picture, 2616}, {«class icns», 43336},
- {«class furl», 62}}
- textutil -convert html foo.rtf
- if ((clipboard info) as string) contains "«class furl»" then
- log "the clipboard contains a file named " & (the clipboard as string)
- else
- log "the clipboard does not contain a file"
- end if
- the clipboard required
- as class optional
- tell application "Script Editor"
- activate
- end tell
- textutil has a simplistic text to html conversion
- set clipboardDataQuoted to quoted form of theData
- log "quoted form is " & clipboardDataQuoted
- set toUnix to "/bin/echo -n " & clipboardDataQuoted
- set toUnix to toUnix & " | textutil -convert html -noload -nostore -stdin -stdout "
- log "toUnix is " & toUnix
- set fromUnix to do shell script toUnix
- log "fromUnix is " & fromUnix
- set s to "Today is my birthday"
- log text 1 thru ((offset of "my" in s) - 1) of s
- --> "Today is "
- -- text 1 thru ((offset of "my" in s) - 1) of s
- -- -1 since offset return the first character "m" position count
- log "beginningOfTag is " & text 1 thru (minimumPositiveNumber from {200, length of beginningOfTag}) of beginningOfTag & "<+++++++++++++++++++++++"
- https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html
- *)
- --mac $ hex=`echo -n "<p>your html code here</>" | hexdump -ve '1/1 "%.2x"'`
- --mac $ echo $hex
- --3c703e796f75722068746d6c20636f646520686572653c2f3e
- --mac $ osascript -e "set the clipboard to «data HTML${hex}»"
- --mac $
- (*
- A sub-routine for encoding ASCII characters.
- encode_char("$")
- --> returns: "%24"
- based on:
- https://www.macosxautomation.com/applescript/sbrt/sbrt-08.html
- *)
- (*
- Lowest Numeric Value in a List
- 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:
- lowest_number({-3.25, 23, 2345, "sid", 3, 67})
- --> returns: -3.25
- lowest_number({-3.25, 23, {-22, 78695, "bob"}, 2345, true, "sid", 3, 67})
- --> returns: -22
- If there is no numeric data in the passed list, the sub-routine will return a null string ("")
- lowest_number({"this", "list", "contains", "only", "text"})
- --> returns: ""
- https://macosxautomation.com/applescript/sbrt/sbrt-03.html
- Here's the sub-routine:
- *)
- (*
- on lowestNumber(values_list)
- set the low_amount to ""
- repeat with i from 1 to the count of the values_list
- set this_item to item i of the values_list
- set the item_class to the class of this_item
- if the item_class is in {integer, real} then
- if the low_amount is "" then
- set the low_amount to this_item
- else if this_item is less than the low_amount then
- set the low_amount to item i of the values_list
- end if
- else if the item_class is list then
- set the low_value to lowest_number(this_item)
- if the the low_value is less than the low_amount then ¬
- set the low_amount to the low_value
- end if
- end repeat
- return the low_amount
- end lowestNumber
- https://lists.apple.com/archives/applescript-users/2010/Sep/msg00139.html
- set list_of_values to {10, 20, 30, 40, 50, 60, 2000, 9, 3000, 4}
- set minimum to 9.9999999999E+12
- set maximum to 0
- repeat with ref_to_value in list_of_values
- set the_value to contents of ref_to_value
- if the_value > maximum then set maximum to the_value
- if the_value < minimum then set minimum to the_value
- end repeat
- {minimum, maximum}
- may do the trick.
- Yvan KOENIG (VALLAURIS, France) lundi 13 septembre 2010 22:32:41
- *)
- (* https://lists.apple.com/archives/applescript-users/2010/Sep/msg00139.html
- set list_of_values to {10, 20, 30, 40, 50, 60, 2000, 9, 3000, 4}
- set minimum to 9.9999999999E+12
- assume it's limited to positive values
- on maxValue(list_of_values)
- global debug
- if debug ≥ 5 then log "in maxValue " & return & list_of_values
- set maximum to 0
- repeat with ref_to_value in list_of_values
- set the_value to contents of ref_to_value
- if the_value > maximum then set maximum to the_value
- end repeat
- if debug ≥ 5 then log maximum
- return maximum
- end maxValue
- *)
- -- ------------------------------------------------------
- (*
- http://harvey.nu/applescript_url_encode_routine.html
- on urlencode(theText)
- set theTextEnc to ""
- repeat with eachChar in characters of theText
- set useChar to eachChar
- set eachCharNum to ASCII number of eachChar
- if eachCharNum = 32 then
- set useChar to "+"
- 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
- set firstDig to round (eachCharNum / 16) rounding down
- set secondDig to eachCharNum mod 16
- if firstDig > 9 then
- set aNum to firstDig + 55
- set firstDig to ASCII character aNum
- end if
- if secondDig > 9 then
- set aNum to secondDig + 55
- set secondDig to ASCII character aNum
- end if
- set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
- set useChar to numHex
- end if
- set theTextEnc to theTextEnc & useChar as string
- end repeat
- return theTextEnc
- end urlencode
- Clipboard classes after a copy from the application.
- from waterfox
- (*«class HTML», 13876, «class utf8», 505, «class ut16», 1012, string, 505, Unicode text, 1010*)
- from chrome
- (*«class HTML», 748, «class utf8», 204, «class ut16», 410, string, 204, Unicode text, 408*)
- from safari
- (*«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*)
- iCab
- (*«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*)
- Opera
- (*«class HTML», 5767, «class utf8», 150, «class ut16», 302, string, 150, Unicode text, 300*)
- Textedit
- (*«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*)
- Word
- (*«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*)
- TextWrangler
- (*«class utf8», 185, «class BBLM», 4, «class ut16», 372, string, 185, Unicode text, 370, «class BBLM», 4*)
- *)
- (*
- 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 \"
- Run etrecheck. The
- first five runs are free. Provided a report on your
- machines hardware and software. Great for diagnosing your system. Click on the download
- link at the bottom of the screen.
- <a href=\"http://etrecheck.com/\" target=\"_blank\">EtreCheck</a></p><p></p>
- <p></p><p>
- <ol>
- <li>point 1</li>
- <li>point 2</li>
- <li>point 3</li>
- </ol>
- </p>
- <p>the end</p>
- "
- *)
- (* set the clipboard to "<p>Simple put, Apple attempts
- to provide all the
- malware detection and removal you need in Mac OS X.</p>
- <p></p><p></p><p></p>
- <p>\"Effective defenses against malware and other threats\" by John Galt
- <a href=\"https://discussions.apple.com/docs/DOC-8841\" target=\"_blank\">Effective
- defenses against malware and ot… - Apple Community</a>
- </p><pre>
- code line #a
- code line #b
- code line #c
- </pre><p> </p><p>\"Avoid phishing emails, fake 'virus' alerts, phony support calls, and other scams\"
- <a href=\"https://support.apple.com/en-ca/HT204759\">Avoid phishing emails, fake
- 'virus' alerts, phony support calls, and other scams - Apple Support</a>
- <pre>
- code line #1
- code line #2
- code line #3
- </pre>"
- *)
- (*
- set the clipboard to "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
- <html>
- <head>
- <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
- <title>asc roger's help text</title>
- </head>
- <body>
- <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
- <span style=\"font-weight: bold; font-family: Lucida Grande;\">App-Specific
- passwords</span> (copy direct,
- clean up returns)<br>
- <br>
- There are apps in the Play Store to sync calendars and contacts -
- search on
- Smoothsync for two of the best. <br>
- <br>
- iCloud mail is standard IMAP and you
- can access it in the mail application using the settings here:<br>
- <br>
- <a href=\"https://support.apple.com/HT202304\">https://support.apple.com/HT202304</a><br>
- <br>
- 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.<br>
- <br>
- <a href=\"https://support.apple.com/HT204915\">https://support.apple.com/HT204915</a><br>
- <br>
- <a href=\"https://support.apple.com/HT204397\">https://support.apple.com/HT204397</a><br>
- <br>
- If you are unable to set up two-factor authentication you should set
- up
- 2-step verification and use that to create an app-specific password
- (see link below) . Then go
- to https://appleid.apple.com , select 'Password and Security'; click
- 'Generate an App-Specific
- Password' and follow the instructions. Once you have the password,
- copy
- it and paste it into the password field in the application instead
- of
- your usual iCloud password. You should also keep a note of it
- (though
- you can generate a new one if required).<br>
- <br>
- <a href=\"https://support.apple.com/kb/HT204152\">https://support.apple.com/kb/HT204152</a><br>
- <br>
- You will need to nominate a 'trusted device' - any phone capable of
- receiving SMS messages. There will be a 2-day wait before you can
- complete the process.<br>
- (A particular caveat (about 2-step only) - you will be issued with a
- 'Recovery Key' in case you lose your 'trusted device'. Make sure to
- write this down and keep it in a safe place; if you lose both it and
- your trusted device you will be permanently locked out of your ID.
- You'd be surprised at the number of people who've posted here that
- they've got themselves into just that position.)<br>
- <br>
- Incidentally, Mail on Snow Leopard and earlier is not recognized as
- an
- Apple application because it's pre-iCloud and doesn't have the
- necessary facilities, so it will be necessary to obtain an
- app-specific
- password for that.
- </body>
- </html>
- <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
- <html>
- <head>
- <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
- <title>asc roger's help text</title>
- </head>
- <body>
- <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
- <span style=\"font-weight: bold; font-family: Lucida Grande;\">App-Specific
- passwords</span> (copy direct,
- clean up returns)<br>
- <br>
- There are apps in the Play Store to sync calendars and contacts -
- search on
- Smoothsync for two of the best. <br>
- <br>
- iCloud mail is standard IMAP and you
- can access it in the mail application using the settings here:<br>
- <br>
- <a href=\"https://support.apple.com/HT202304\">https://support.apple.com/HT202304</a><br>
- <br>
- 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.<br>
- <br>
- <a href=\"https://support.apple.com/HT204915\">https://support.apple.com/HT204915</a><br>
- <br>
- <a href=\"https://support.apple.com/HT204397\">https://support.apple.com/HT204397</a><br>
- <br>
- If you are unable to set up two-factor authentication you should set
- up
- 2-step verification and use that to create an app-specific password
- (see link below) . Then go
- to https://appleid.apple.com , select 'Password and Security'; click
- 'Generate an App-Specific
- Password' and follow the instructions. Once you have the password,
- copy
- it and paste it into the password field in the application instead
- of
- your usual iCloud password. You should also keep a note of it
- (though
- you can generate a new one if required).<br>
- <br>
- <a href=\"https://support.apple.com/kb/HT204152\">https://support.apple.com/kb/HT204152</a><br>
- <br>
- You will need to nominate a 'trusted device' - any phone capable of
- receiving SMS messages. There will be a 2-day wait before you can
- complete the process.<br>
- (A particular caveat (about 2-step only) - you will be issued with a
- 'Recovery Key' in case you lose your 'trusted device'. Make sure to
- write this down and keep it in a safe place; if you lose both it and
- your trusted device you will be permanently locked out of your ID.
- You'd be surprised at the number of people who've posted here that
- they've got themselves into just that position.)<br>
- <br>
- Incidentally, Mail on Snow Leopard and earlier is not recognized as
- an
- Apple application because it's pre-iCloud and doesn't have the
- necessary facilities, so it will be necessary to obtain an
- app-specific
- password for that.
- </body>
- </html>
- "
- adustDuplicateAnchorURLs("<a href=\"https://support.apple.com/en-ca/HT204759\">https://support.apple.com/en-ca/HT204759</a>")
- 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>")
- return
- *)
- (*
- on trimCharacters(inputTrim, outputTrim, reduce)
- global debug
- set charactersTrimmed to ""
- if debug ≥ 3 then
- log "in ~~~ trimCharacters ~~~"
- log " trimCharacters: length of inputTrim is " & getIntegerAndHex(length of inputTrim)
- hexDumpFormatOne(" trimCharacters: inputTrim", inputTrim)
- log " trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
- hexDumpFormatOne(" trimCharacters: outputTrim", outputTrim)
- log " trimCharacters: with reduce >" & reduce & "< "
- end if
- set repCount to 1
- repeat while length of inputTrim ≥ 1 and text 1 thru 1 of inputTrim is reduce
- set charactersTrimmed to charactersTrimmed & reduce
- set {inputTrim, outputTrim} to trimOneChar(inputTrim, outputTrim, 1, "")
- if debug ≥ 6 then
- log " trimCharacters: repCount is " & repCount
- set repCount to repCount + 1
- log " trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
- hexDumpFormatOne(" trimCharacters: cycling inputTrim", inputTrim)
- log " trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
- hexDumpFormatOne(" trimCharacters: cycling outputTrim", outputTrim)
- end if
- end repeat
- if debug ≥ 3 then
- log " trimCharacters: length of inputTrim is" & getIntegerAndHex(length of inputTrim)
- hexDumpFormatOne(" trimCharacters: completed inputTrim", inputTrim)
- log " trimCharacters: length of outputTrim is " & getIntegerAndHex(length of outputTrim)
- hexDumpFormatOne(" trimCharacters: completed outputTrim", outputTrim)
- log " trimCharacters: charactersTrimmed is " & charactersTrimmed
- log "bye from ~.~ trimCharacters ~.~"
- end if
- return {inputTrim, outputTrim, charactersTrimmed}
- end trimCharacters
- *)
- (*
- -- ------------------------------------------------------
- --
- -- print out the items in a list
- --
- --
- on printList(theName, splits)
- global debug
- if debug ≥ 5 then log "in ~~~ printList ~~~"
- try
- set theCount to 1
- repeat with theEntry in splits
- --log "class of theEntry is " & class of theEntry
- set classDisplay to class of theEntry as text
- --log "classDisplay is " & classDisplay as text
- --log "class of classDisplay is " & class of classDisplay
- if classDisplay is "list" then
- log " " & theName & " # " & theCount & " is " & item 1 of theEntry & "; " & item 2 of theEntry
- else
- log " " & theName & " # " & theCount & " is " & theEntry
- end if
- set theCount to theCount + 1
- end repeat
- on error errMsg number n
- log "==> No go in printList. " & errMsg & " with number " & n
- end try
- end printList
- *)
- (*
- tell application "Finder"
- --set theFiles to (files in folder (choose folder))
- --reveal theFiles
- end tell
- tell application "Finder"
- -- set theFile to (choose file)
- --reveal theFiles
- end tell
- set theFiles to {¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:Paralles virtual machine -<a ... - html.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc appleid login.txt", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example longer text conversion few line ends.txt", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example longer text conversion.txt", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with .html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with <pre> with <head> \"Waterfox\".html", ¬
- 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", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with <pre>.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list with lf & <pre>.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc example text conversion with list.txt", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test \"Waterfox\".html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test with no begin title.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test with no end title.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test with title.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc file test.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc from Roger on Jiune 11th.htm..html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc insert title in <a>.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc isolate a Roger issue.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc link problem form Roger.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc list test for ASC.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc mangle tags via \\\".html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc my script froze on.txt", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc roger's help text.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc single ul and p with links.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc spacing test with backslash.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:asc spacing test.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:links and list of numbers.txt", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:littlebittytest.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:roger's troubles.html", ¬
- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:CyberDuck demo.html"}
- -- debuging for openContinued. Displays timed display dialogs.
- set localDebug to false
- -- true displayed timed dialogs
- -- false skip debuging
- set debugSeparator to true
- -- true place a separator between the output of dropped files
- -- false nothing is added
- -- alias "Macintosh SSD:Users:mac:Documents:css-12-15-2018:ASC Testing:roger's troubles.html"
- printList("theFiles are ", theFiles)
- --log theFiles
- openContinued(theFiles, localDebug, debugSeparator)
- return 1
- *)
- (*
- 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>"
- skipDoctype("", myInput)
- return
- *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement