Thursday, August 11, 2022

#1 2022-06-28 07:21:07 am

epaminos
Member
From:: Greece
Registered: 2019-10-18
Posts: 94

Simple clipboard tool

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

 

#2 2022-06-28 10:55:46 am

estockly
Member
Registered: 2009-01-03
Posts: 80

Re: Simple clipboard tool

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

 

#3 2022-06-29 04:52:51 am

epaminos
Member
From:: Greece
Registered: 2019-10-18
Posts: 94

Re: Simple clipboard tool

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

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)