You are not logged in.
Hi team,
I would like your valuable advice for a very simple task.
So, I want to create a script that gets the contents of the clipboard as paragraphs, gets rids of the empty lines, then it pastes only the first paragraph and saves the rest of the paragraphs (without the first line) in the clipboard.
So far I developed the following, but cannot be applied the second time. Any help please?
set {var, endList} to {the clipboard, {}}
repeat with x in paragraphs of var
set endList to endList & x
end repeat
if item 1 of endList is "" or item 1 of endList is " " or item 1 of endList is "
" or item 1 of endList is {} or length of item 1 of endList is less than 1 then
else
set the clipboard to first item of endList
delay 0.1
tell application "System Events" to keystroke (the clipboard as text)
set new_clip to rest of endList
set the clipboard to new_clip
end if
Last edited by epaminos (2022-06-28 07:22:00 am)
Offline
Try something like this:
Applescript:
set myText to paragraphs of (the clipboard)
set filteredText to {}
repeat with thisGraph in myText
if thisGraph is not in {"", " ", tab} then set the end of filteredText to thisGraph as item
end repeat
set textToPaste to item 1 of filteredText as text
set AppleScript's text item delimiters to {return}
set the clipboard to the rest of filteredText as text
----paste textToPaste here---
Offline
Awesome! Thank you, it worked!
I just added a message as well:
Applescript:
set myText to paragraphs of (the clipboard)
set filteredText to {}
repeat with thisGraph in myText
if thisGraph is not in {"", " ", tab} then set the end of filteredText to thisGraph as item
end repeat
if filteredText = {} or length of filteredText < 1 then
display dialog "The clipboard is empty." buttons {"OK"}
else
set textToPaste to item 1 of filteredText as text
set AppleScript's text item delimiters to {return}
set the clipboard to the rest of filteredText as text
tell application "System Events" to keystroke (textToPaste as text)
end if
Last edited by epaminos (2022-06-29 04:53:31 am)
Offline