Monday, October 26, 2020
  • Index
  •  » Automator
  •  » edit lines of text coming from "filter Paragraphs" action on automator

#1 2020-10-05 03:55:00 am

samh
Member
Registered: 2020-10-04
Posts: 8

edit lines of text coming from "filter Paragraphs" action on automator

Hello, i'm very new to scripting and automator so thank you for taking my newbie questions.

I filtered a text file, and am getting it separated by the parts of text I need, and then joined again as I need.
For this, I'm using automator actions and it's working.
But before each part is saved I need to clean some more and I'm wondering if a script after "filter paragraphs" action and before "new text file" action would do the thing.

On 01.txt:
I need this
SESSION NAME:    Yaddayaddayadda
SESSION NAME:    Yaddayaddayadda

to become
SESSION NAME:    Yaddayaddayadda




on 02.txt:
from this
CHANNEL     EVENT       CLIP NAME                         START TIME        END TIME          DURATION          STATE
CHANNEL     EVENT       CLIP NAME                         START TIME        END TIME          DURATION          STATE
CHANNEL     EVENT       CLIP NAME                         START TIME        END TIME          DURATION          STATE

to this
CLIP NAME                         START TIME        END TIME          DURATION


the number of lines can be from one to hundreds, I need only the first one



on 03.txt
from this
1           2           whoosh 003_.L                        00:03:52:21       00:03:53:18       00:00:00:21    Unmuted
1           2           whoosh 003_.L                        00:03:52:21       00:03:53:18       00:00:00:21    Unmuted
1           2           whoosh 003_.L                        00:03:52:21       00:03:53:18       00:00:00:21    Unmuted
1           2           whoosh 003_.L                        00:03:52:21       00:03:53:18       00:00:00:21    Unmuted

to this
whoosh 003_.L                        00:03:52:21       00:03:53:18       00:00:00:21




these lines can be hundreds, I need them all but without the first numbers and spaces and last word "Unmuted"



Thank you so much

Offline

 

#2 2020-10-05 05:13:28 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5299

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hi samh. Welcome to MacScripter.

If I've understood you correctly, the following AppleScript should cover all three cases. The "Run AppleScript" action containing it should go immediately after the "Filter Paragraphs" action(s). Note that it edits any line beginning with "CHANNEL" or a number, so if that's not suitable in all cases, it'll need to be modified or rewritten as separate scripts. Its output is a single text, but if you want the output as separate lines, like the output from "Filter Paragraphs", there's a note in the script about how to get that.

Applescript:

(* Filter out duplicate paragraphs. Edit those beginning with "CHANNEL" or a number. *)

-- input: list of paragraphs returned by the Automator "Filter Paragraphs" action.
-- parameters: not used.
-- output: result as a single text.
on run {input, parameters}
   set output to {}
   repeat with thisLine in input
       if ((thisLine begins with "CHANNEL") or (character 1 of thisLine is in "0123456789")) then
           set thisLine to text from word 3 to word -2 of thisLine
       end if
       if (thisLine is not in output) then set end of output to thisLine as text
   end repeat
   
   -- The following four lines convert the list of output lines to a single text.
   -- Delete them if not wanted.
   set astid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to linefeed
   set output to output as text
   set AppleScript's text item delimiters to astid
   
   return output
end run


NG

Offline

 

#3 2020-10-05 05:42:01 am

samh
Member
Registered: 2020-10-04
Posts: 8

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hello Nigel,
Thank you so much for your reply.

when I put the script on a "run applescript" action it returns no erros, but running the automator I get this,
!The action “Run AppleScript” encountered an error: “Can’t make character 1 of item 1 of {current application, current application, current application, current application, current application, current application, current application} into type Unicode text.”!

and there is no output

could you help me with what I'm doing wrong?

thank you so much

Offline

 

#4 2020-10-05 06:42:05 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5299

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hi samh.

Are you placing the "Run AppleScript" action immediately after "Filter Paragraphs"? As far as I can see, and according to my tests this morning, the latter's supposed to return a list of texts representing the filtered paragraphs (or lines in your case). Whatever's being reported as 'current application' certainly isn't text!

What's your input to "Filter Paragraphs"? It works for me both with a complete text and with a list of individual paragraphs.


NG

Offline

 

#5 2020-10-05 06:46:26 am

samh
Member
Registered: 2020-10-04
Posts: 8

Re: edit lines of text coming from "filter Paragraphs" action on automator

I managed to make it work but not on my main automator.
I think the mistake is because I'm receiving to filter, text from the clipboard.

could this be the case?
How do I fix it?

Thank you

Offline

 

#6 2020-10-05 06:59:32 am

samh
Member
Registered: 2020-10-04
Posts: 8

Re: edit lines of text coming from "filter Paragraphs" action on automator

It only works after a filter text thing,

but if the text to be filtered comes from clipboard, it fails.

Offline

 

#7 2020-10-05 08:31:13 am

samh
Member
Registered: 2020-10-04
Posts: 8

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hello Nigel,

Thank you so much, I changed my workflow to allow the script to work properly.

It's now doing everything

Thank you

Offline

 

#8 2020-10-05 01:13:16 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5299

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hi samh.

I'm glad you've got something that's working for you. It does seem to be the clipboard actions that were causing the problem. It's not usually necessary to use the clipboard in an automated process, but the same happens when Automator's variables are used instead. I'm pretty sure it's a bug. An action which recognises and filters paragraphs should be passing text to the next action in the sequence!  hmm


NG

Offline

 

#9 2020-10-07 04:43:54 pm

samh
Member
Registered: 2020-10-04
Posts: 8

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hello Nigel,

I'm trying to simplify the workflow I made once I noticed how clean your script makes everything.
Is it possible to add to the script delete every line starting with:

SAMPLE RATE:
BIT DEPTH:
SESSION START TIMECODE (there is another line starting with SESSION that can't be deleted)
TIMECODE FORMAT:
# OF AUDIO TRACKS:
# OF AUDIO CLIPS:
# OF AUDIO FILES:
T R A C K  L I S T I N G
TRACK NAME:
COMMENTS:   
USER DELAY:
STATE:

Thank you so much

Last edited by samh (2020-10-07 04:44:54 pm)

Offline

 

#10 2020-10-08 03:59:10 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5299

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hi samh.

I think this covers all eventualities (Automator bugs and non-text input excepted). The input from the preceding action can be either a whole text or a list of its paragraphs and you can edit the "unwanteds" list if you need to make any changes there. Everything else is as before.

Applescript:

on run {input, parameters}
   -- Automator's "Run AppleScript" actions appear always to receive their input in list form.
   -- If the input here contains only one item, and it's text, get a list of the text's 'paragraphs'.
   if (((count input) is 1) and (class of item 1 of input is text)) then
       set input to paragraphs of item 1 of input
   end if
   
   set unwanteds to {"SAMPLE RATE:", "BIT DEPTH:", "SESSION START TIMECODE", ¬
       "TIMECODE FORMAT:", "# OF AUDIO TRACKS:", "# OF AUDIO CLIPS:", ¬
       "# OF AUDIO FILES:", "T R A C K L I S T I N G", "TRACK NAME:", ¬
       "COMMENTS:", "USER DELAY:", "STATE:"}
   
   set output to {}
   repeat with thisLine in input
       set OKSoFar to true
       repeat with thisBeginning in unwanteds
           if (thisLine begins with thisBeginning) then
               set OKSoFar to false
               exit repeat
           end if
       end repeat
       if (OKSoFar) then
           if ((thisLine begins with "CHANNEL") or (character 1 of thisLine is in "0123456789")) then
               set thisLine to text from word 3 to word -2 of thisLine
           end if
           if (thisLine is not in output) then set end of output to thisLine as text
       end if
   end repeat
   
   -- The following four lines convert the list of output lines to a single text.
   -- Delete them if not wanted.
   set astid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to linefeed
   set output to output as text
   set AppleScript's text item delimiters to astid
   
   return output
end run


NG

Offline

 

#11 2020-10-08 08:54:49 am

samh
Member
Registered: 2020-10-04
Posts: 8

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hello Nigel,
so far its looking great,

Thank you so so much!!

Offline

 

#12 2020-10-14 05:48:31 am

samh
Member
Registered: 2020-10-04
Posts: 8

Re: edit lines of text coming from "filter Paragraphs" action on automator

Hello Nigel,
Here's a link to the hole workflow you helped me with.
Thank you so much.
https://www.facebook.com/groups/soundfl … 513465810/

Offline

 
  • Index
  •  » Automator
  •  » edit lines of text coming from "filter Paragraphs" action on automator

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)