Convert ASC double returns to a single return
When user Firefox and you copy and paste ASC text into another editor, you get two returns for every return on the ASC web page. This appears to be a Firefox "feature/bug". The Applescript convert the double returns to a single return.
(*
Name: alter-clipboard
Input: Clipboard
Output: Clipboard
This AppleScript program is designed to convert the ASC double returns find in the copy/paste buffer to a single return.
Author: rccharles
Copyright 2017 rccharles
GNU General Public License
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
For a copy of the GNU General Public License see <http://www.gnu.org/licenses/>.
*)
on run
-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "
(* ... supports three file formats:
unix (lines end with LF),
dos (lines end with CR LF), and
mac (lines end with CR).
http://vim.wikia.com/wiki/Change_end-of-line_format_for_dos-mac-unix *)
set lf to ASCII character 10
set theClip to the clipboard
if length of theClip = 0 then
display dialog "Please copy something to the clip board." giving up after 20
return
else
display dialog "converting text..." giving up after 2
end if
-- see http://www.asciitable.com/ for the ASCII translations
-- change '0D0D'x to '0D'x
set theClip to alterString(theClip, return & return, return)
-- set theClip to alterString(theClip, return & lf, return)
set the clipboard to theClip
end run
-- ----------------------------------------------------------------------
on alterString(thisText, delim, replacement)
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
-- ----------------------------------------------------------------------
-- textToList was found here:
-- http://macscripter.net/viewtopic.php?id=15423
on textToList(thisText, delim)
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 textToListHere is what is copied from an ASC web page.
Here is the result shown in TextWrangler.
R