Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12
  1. #11
    Join Date
    Jan 2012
    Posts
    22

    Default Linux - Doc to Text file method

    Ok, here's the method for converting to plain text, in-case other Linux users want to go this way:

    Add another macro into OpenOffice
    Code:
    ' Save document as Text file.
    Sub SaveAsText( cFile, cOutFile )
       cURL = ConvertToURL( cFile )
       ' Open the document. Just blindly assume that the document
       ' is of a type that OOo will correctly recognize and open
       ' without specifying an import filter.
       oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(MakePropertyValue( "Hidden", True )))
    
       ' cFile = Left( cFile, Len( cFile ) - 4 ) + ".html"
       cURL = ConvertToURL( cOutFile )
       
       ' Save the document using a filter.   
       oDoc.storeToURL( cURL, Array(_
                MakePropertyValue( "FilterName", "Text (encoded)" ),)
       
       oDoc.close( True )
    End Sub
    create another bash script, eg, "bc_word_to_text" (PS. don't forget to do a "chmod +x bc_word_to_text" to make it executable).

    Code:
    #!/bin/bash
    
    # --------------------------
    # FUNCTION
    # --------------------------
    
    function waitSOfficeClose {
    export SOFFICE_ACTIVE=`ps aux | grep soffice | grep macro`
    while [ "$SOFFICE_ACTIVE" != "" ]
    do
        echo "$$ : sleeping 1..."
    	sleep 1
    	export SOFFICE_ACTIVE=`ps aux | grep soffice | grep macro`
    done
    }
    
    
    # --------------------------
    # MAIN
    # --------------------------
    
    echo "$$ : starting..."
    echo $$ : soffice --invisible ""macro:///Standard.Module1.SaveAsText\($1,$2\)""
    
    waitSOfficeClose
    
    konsole -e soffice --invisible "macro:///Standard.Module1.SaveAsText($1,$2)"
    
    echo "$$ : soffice was run!"
    
    sleep 1
    
    waitSOfficeClose
    
    echo "$$ : exit..."
    Then make the format-rule in BC3 to be:

    Code:
    bc_word_to_text "%s" "%t"

    Post Edit History:

    • (20/08/2013) - More fixes to the "bc_word_to_text" script
      • bcompare will trigger the script twice for LHS and RHS instantaneously. So assure only one call to soffice at a time.
      • After starting soffice, wait a second prior to testing if soffice has closed
    • (09/02/2012) - The script needs to wait for the soffice macro process to complete before exiting the script
    Last edited by Gurce; 19-Aug-2013 at 11:05 PM. Reason: A bit of cleanup

  2. #12
    Join Date
    Oct 2007
    Location
    Madison, WI
    Posts
    4,610

    Default

    Gurce,

    Thank you for sharing, I'm sure some of our Linux users will find it useful.
    Chris K Scooter Software

Tags for this Thread

Posting Permissions

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