Professional Web Applications Themes

Newbie needs Tex-Edit Plus and Applescript help - Mac Programming

hey all, newbie here: I am just starting out writing my first script. I have transcripts that include timecode values at the end of each line of text, followed by a carriage return (cr). The timecode values are in this format: "00:00:00" I need to do three things with them. The first step I was able to accomplish with help from Tom Bender. Step 1. append ".00" to the end of each timecode, and enclose in brackets "[ ]" Step 2. delete all lines/paragraphs in the doent file that do NOT have a timecode value Step 3. move the timecode ...

  1. #1

    Default Newbie needs Tex-Edit Plus and Applescript help

    hey all, newbie here:

    I am just starting out writing my first script. I have transcripts
    that include timecode values at the end of each line of text, followed
    by a carriage return (cr). The timecode values are in this format:
    "00:00:00"

    I need to do three things with them. The first step I was able to
    accomplish with help from Tom Bender.

    Step 1. append ".00" to the end of each timecode, and enclose in
    brackets "[ ]"

    Step 2. delete all lines/paragraphs in the doent file that do NOT
    have a timecode value

    Step 3. move the timecode value to the beginning of the line on which
    it resides

    Here is what I have so far. Can anybody give me an assist?

    TIA,

    oobi



    on open droppedFile
    tell application "Tex-Edit Plus"
    activate
    open droppedFile
    replace window 1 looking for "[0-9]{2}:[0-9]{2}:[0-9]{2}" replacing
    with "[^0.00]" with grep
    end tell

    --works o.k. The following is my last attempt to work out Step #2
    --------------------------------------------------------------------------------
    tell application "Tex-Edit Plus"
    activate window 1
    if paragraph contains "([[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2}])" then
    else
    delete (every paragraph whose contents contains
    "([[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2}])")
    end if
    end tell

    --not working; I have tried everything I know (which is not much). I
    tried including the grep languge used previously, I tried different
    combinations of "", parentheses, and additional regular expressions,
    but I am stuck.
    oobi Guest

  2. #2

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    Entity oobi spoke thus:
     
    In all honesty, I have never been able to use regex in Tex-Edit. All my text
    manipulation I now do with shell scripting. Tex-Edit scripting is best when
    limited to styles and such.

    It shouldn't be too hard to do what you want, can you post a short segment
    of the before-and-after text to get us going?

    -- Gnarlie's Applescript page
    http://www.Gnarlodious.com/OSX/AppleScript/AppleScript.html

     

    Gnarlodious Guest

  3. #3

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    Certainly:


    1. The rain in Spain falls gently on the plain. [00:01:02.03]
    2. Do you know the way to San Jose? [00:01:04.00]


    --into--

    [00:01:03.03] 1. The rain in Spain falls gently on the plain.
    [00:01:04.00] 2. Do you know the way to San Jose?



    TIA



    ---------------------------------- 
    oobi Guest

  4. #4

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    * oobi <com>, 2004-02-16 12:44 +0100: 

    I have no idea as of how this is to be done in AppleScript, but you
    need positional parameters like '\(blahblah\)' in the regexp. If it
    was in sed, I'd suggest:

    sed -e "s/\(^.*\)\(\[.*\]\)$/\2 \1/" < infile > outfile
    ^^^^^^^ pos1: beginning of line ^ to next regexp
    ^^^^^^^^^^^ pos2: from first [ to end of line $
    ^^^^^ reorder: pos2 blank pos1
    ^^^^^^^^ read from infile
    ^^^^^^^^^ write result to outfile

    This is based strictly on the example you gave. If the text contained
    "["s itself, you'd have to make the regexp less greedy, i.e. make
    sure it matches only timestamps in square brackets.

    I hope this helps,

    -Andre

    Andre Guest

  5. #5

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    * Andre Berger <de>, 2004-02-16 13:19 +0100: 
    >
    > I have no idea as of how this is to be done in AppleScript, but you
    > need positional parameters like '\(blahblah\)' in the regexp. If it
    > was in sed, I'd suggest:
    >
    > sed -e "s/\(^.*\)\(\[.*\]\)$/\2 \1/" < infile > outfile
    > ^^^^^^^ pos1: beginning of line ^ to next regexp
    > ^^^^^^^^^^^ pos2: from first [ to end of line $[/ref]
    Sorry, I meant: to ] at end of line $ 

    -Andre

    Andre Guest

  6. #6

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    In article <google.com>,
    com (oobi) wrote:
     

    um, why not do 2 before/at the same time as 1?

    simpler answer for that stage given your description of the file:

    replace window 1 looking for ":00^c" replacing with ":00.00^c"

    not speaking as a grepper, i'm guessing it will not make much time
    difference if you just step through line by line for the other two
    items, and do simple tests on each line. if the non-code lines never
    end with "0" (compare against "last character of line x") it's absurdly
    easy. just remember to start with the last paragraph, not the first, so
    you don't skip any lines when you delete a non-timecode line.

    --
    David J Richardson -- name
    http://davidj.richardson.name/ -- Dr Who articles/interviews/reviews
    http://www.boomerang.org.au/ -- Boomerang Association of Australia
    David Guest

  7. #7

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    * Andre Berger <de>, 2004-02-16 13:26 +0100: [/ref]

    Sorry to follow-up to my own postings; I thought you might be
    interested in a shell script procedure to should do everything you
    want in one go.

    cat infile | egrep "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]" | sed -e "s/\(^.*\)\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\)\(.*\)$/\[\2.00\] \1\3/" > outfile

    (This is one long line)

    egrep is used to feed sed with lines with timestamp only. Sed splits
    the lines into "prepends-timestamp", "timestamp-itself",
    "trails-timestamp", then outputs

    ["timestamp-itself".00] "prepends-timestamp""trails-timestamp"

    Could be done differently and more elegant as usual.

    As for your original AppleScript example #2, instead of if/else with
    an empty if statement, use the logical NOT "!" in your regexp to
    delete paragraphs containing what you don't want.

    I hope this helps,

    -Andre

    Andre Guest

  8. #8

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    Entity Andre Berger spoke thus:
     [/ref]
     

    This works for me, to do it in Applescript say:


    set inputFile to "user:Desktop:inputFile" as alias -- "as alias" says file
    must already exist
    set outputFile to "user:Desktop:outputFile" -- file doesn't exist

    do shell script "sed -e 's|\\(^.*\\)\\(\\[.*\\]\\)$|\\2 \\1|' " & POSIX path
    of inputFile & " > " & POSIX path of outputFile



    Note that in Applescript two mods apply:
    1) You must escape "\" characters by doubling them.
    2) You can use the "|" character as an optional field separator instead of
    Terminal's "/".

    You can bypass the POSIX translations and say:
    do shell script "sed -e 's/\(^.*\)\(\[.*\]\)$/\2 \1/'
    ~user/Desktop/inputFile > ~user/Desktop/outputFile"

    This approach is drastically faster where many files are moved.

    Remember to unwrap these lines to run them in Applescript

    If ypu want a detailed explanation of how UNIX command "sed" works, just
    ask.

    -- Gnarlie's Applescript page
    http://www.Gnarlodious.com/OSX/AppleScript/AppleScript.html

    Gnarlodious Guest

  9. #9

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    In article <local>,
    Andre Berger <de> wrote:
     

    It should be noted for those unexperienced with these things that
    'infile' and 'outfile' should never be the same file. If you do that,
    the shell will happily empty the file for you.
    Michael Guest

  10. #10

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    Thank you, one and all.

    My head just exploded :-)

    I have absolutely no other scripting background or experience so, I
    will need a moment to.......GOOGLE EVERYTHING YOU ALL JUST SAID!!

    I will try out these suggestions....
    When I am able to formulate coherent followup questions, I will
    re-post. I do have one question: I have been limiting my reformatting
    within the Tex-Edit application. Do many (most?) of these expressions
    not require any application in particular? If Tex-Edit isn't
    neccessary to perform these, what then? Any window in the finder?

    much appreciation,
    -oobi
    oobi Guest

  11. #11

    Default Re: Newbie needs Tex-Edit Plus and Applescript help

    Entity oobi spoke thus:
     
    Shell scripting is a whole new dimension all right.
     
    Sed is for StreamEDitor. When you use a word processor, it is simply a GUI
    to shell commands. At least in UNIX.
     
    TE is a GUI and the limited REGEX used is applicable in shell also. For an
    example see my TE script here, which was for Classic:
    <http://www.Gnarlodious.com/OSX/AppleScript/iCab-iPageClassic.html>

    Compared to this script for OSX and uses many same expressions:
    http://www.Gnarlodious.com/OSX/AppleScript/iCab-iPage.scpt.html

    Unfortunately TE's text manipulation is very slow and hard to script and is
    only useful for styles and simple reformatting..
     
    Any text doent can be processed, but it must be in UNIX format for some
    shell commands to work, such as the "sort" command.

    If you process a Tex-Edit doent with shell, you will find the styles
    remain stationary while the text moves in it (if you add or remove text).
    This is because shell ignored the Tex-Edit resource. But after processing
    the file can still be opened in TE, and even keeps its icon.
    This is very useful.

    -- Gnarlie

    Gnarlodious Guest

Similar Threads

  1. Newbie Applescript question
    By Alan in forum Mac Applications & Software
    Replies: 1
    Last Post: August 19th, 05:17 PM
  2. Newbie: Can't get HISTORY, EDIT or RUNCMD working
    By Derek Clarkson in forum IBM DB2
    Replies: 0
    Last Post: August 18th, 01:40 AM
  3. Newbie: CBO Properties Edit -> VBA
    By David Cogley in forum Microsoft Access
    Replies: 2
    Last Post: July 4th, 08:52 PM
  4. newbie needs to globally edit his site
    By leegold in forum PERL Miscellaneous
    Replies: 4
    Last Post: July 2nd, 08:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139