The other day I ask help for a script because I am a real dummy with AppleScripts. I have deleted that post and I try by myself to write one. I apologize because is not well coded.
This script takes the content of the clipboard, do some replacements into the text, then retains only line 1, then 5 and following (line 6 is exist, etc…). But I do not know how to do if line 6 and following do not exist.
Here is a sample of the text set to the clipboard:
set theText to the clipboard
set new_string to ""
repeat with this_char from 1 to (count theText)
if item this_char of theText is not "\\" then
set new_string to new_string & item this_char of theText
else
set new_string to new_string & "/"
end if
end repeat
set AppleScript's text item delimiters to "« "
set theItems to text items of theText
set AppleScript's text item delimiters to "''"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " »"
set theItems to text items of theText
set AppleScript's text item delimiters to "''"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to ASCII character 34
set theItems to text items of theText
set AppleScript's text item delimiters to "''"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " ?"
set theItems to text items of theText
set AppleScript's text item delimiters to "?"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " !"
set theItems to text items of theText
set AppleScript's text item delimiters to "!"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " :"
set theItems to text items of theText
set AppleScript's text item delimiters to ":"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " ;"
set theItems to text items of theText
set AppleScript's text item delimiters to ";"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " "
set theItems to text items of theText
set AppleScript's text item delimiters to " "
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set _data to paragraphs of (newText)
set text item delimiters to return
set _newData to (item 1 of _data as string) & return & return
set _newData5 to (item 5 of _data as string) & return & return
set _newData6 to (item 6 of _data as string)
set the clipboard to _newData & _newData5 & _newData6
set theText to the clipboard as text
set new_string to ""
repeat with this_char from 1 to (count theText)
if item this_char of theText is not "\\" then
set new_string to new_string & item this_char of theText
else
set new_string to new_string & "/"
end if
end repeat
set AppleScript's text item delimiters to "« "
set theItems to text items of theText
set AppleScript's text item delimiters to "''"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " »"
set theItems to text items of theText
set AppleScript's text item delimiters to "''"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to ASCII character 34
set theItems to text items of theText
set AppleScript's text item delimiters to "''"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " ?"
set theItems to text items of theText
set AppleScript's text item delimiters to "?"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " !"
set theItems to text items of theText
set AppleScript's text item delimiters to "!"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " :"
set theItems to text items of theText
set AppleScript's text item delimiters to ":"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " ;"
set theItems to text items of theText
set AppleScript's text item delimiters to ";"
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set AppleScript's text item delimiters to " "
set theItems to text items of theText
set AppleScript's text item delimiters to " "
set newText to theItems as text
set AppleScript's text item delimiters to ""
set theText to newText
set _data to paragraphs of (newText)
set text item delimiters to return
set _newData to (item 1 of _data as string) & return & return
set {_newData5, _newData6} to {"", ""}
try
set _newData5 to (item 5 of _data as string) & return & return
end try
try
set _newData6 to (item 6 of _data as string)
end try
set the clipboard to _newData & _newData5 & _newData6
set theText to the clipboard as text
set theText to my remplace(theText, "\\", "/")
set theText to my remplace(theText, {"« ", " »", quote}, "''")
set theText to my remplace(theText, " ?", "?")
set theText to my remplace(theText, " !", "!")
set theText to my remplace(theText, " :", ":")
set theText to my remplace(theText, " ;", ";")
set theText to my remplace(theText, " ", " ")
set _data to paragraphs of theText
if (count _data) < 5 then
set theText to item 1 of _data
else if (count _data) < 6 then
set theText to my recolle({item 1 of _data, item 5 of _data}, return & return)
else
set theText to my recolle({item 1 of _data, item 5 of _data, item 6 of _data}, return & return)
end if
set the clipboard to theText
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end remplace
#=====
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 19 octobre 2019 18:35:48
Because I do not know how many lines can follow line 5, did there is a way to automate this by a counter and a variable. This will avoid hard coding _newline5, _newline6, _newline7, etc…
I just understand that your original data may contain more than 6 paragraphs so I edited again the script.
et theText to the clipboard as text
set theText to my remplace(theText, "\\", "/")
set theText to my remplace(theText, {"« ", " »", quote}, "''")
set theText to my remplace(theText, " ?", "?")
set theText to my remplace(theText, " !", "!")
set theText to my remplace(theText, " :", ":")
set theText to my remplace(theText, " ;", ";")
set theText to my remplace(theText, " ", " ")
repeat with i from 65 to 90
set theText to my remplace(theText, ": " & character id i, ": " & character id (i + 32)) # A detail was hurting my poor eyes
end repeat
set _data to paragraphs of theText
if (count _data) < 5 then
set theText to item 1 of _data
else
set theText to my recolle({item 1 of _data, (get items 5 thru -1 of _data)}, return & return)
end if
set the clipboard to theText
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end remplace
#=====
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 19 octobre 2019 19:15:24
From my point of view, correcting an erroneous E was not sufficient.
I edited the code in message #7 so that it correct every uppercase (non accentuated) inserted after a colon.
I took the opportunity to show you what is the correct syntax to define a character from its Unicode value. ASCII which you used in your original message is deprecated for years.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 19 octobre 2019 20:54:46