4

Any ideas on how I can get:

textutil -convert html file.doc -stdout | pandoc -f html -t markdown -o file.md

so that I can execute the command on a folder and all it's subfolders and so that the markdown file is placed in the same folder as the original?

Francis Avila
  • 31,233
  • 6
  • 58
  • 96
rev
  • 623
  • 1
  • 7
  • 16

2 Answers2

5

Use find with xargs running a subshell

find . -name '*.doc' -print0 | xargs -0 sh -c \
'textutil -convert html "$0" -stdout | pandoc -f html -t markdown -o "${0%.*}.md"'
Francis Avila
  • 31,233
  • 6
  • 58
  • 96
  • cut and pasted the code gives me the following error: `find: -name=*.doc: unknown option` – rev Apr 24 '12 at 14:51
  • pasted thus `find . -name='*.doc' -print0 | xargs -0 sh -c \'textutil -convert html "$0" -stdout | pandoc -f html -t markdown -o "${0%.*}.md"'` All that seems to happen is that my shell prompt changes from `$` to `>`. – rev Apr 24 '12 at 14:53
  • Remove the equal sign, and note that the `\ ` is before a newline, so you have to either paste it that way or remove the `\ ` – Francis Avila Apr 24 '12 at 15:02
  • Thanks Francis. Have used the following code: `find . -name '*.docx' -print0 | xargs -0 sh -c 'textutil -convert html "$0" -stdout | pandoc -f html -t markdown -o "${0%.*}.md"'` and get no error messages, but no file conversions either. I'm using terminal and in the directory containing the files. I've changed the .doc to .docx, but understand textutil can convert those aswell. – rev Apr 24 '12 at 20:40
  • Does `find . -name '*.docx'` print anything? You should run this from the top-level directory which has your files. – Francis Avila Apr 24 '12 at 22:40
  • yep, gives me a list of my .docx files eg: `./01 Contents.docx ./02 Unit Details.docx` – rev Apr 25 '12 at 11:28
1

I found this to work really well on OSX,

https://github.com/dsanson/Pandoc-Droplets-and-Services

I opened one of the .app files and changed it to Makrdown. Saved as new then added it to my finder window.

Any file I want converted I simply drag to the app icon and its converted in the same folder.

Adam Patterson
  • 651
  • 5
  • 11
  • I'm on mountain lion and keep getting, `The action “Run Shell Script” encountered an error.` Any ideas if something has changed with mountain lion to cause an error with the scripts? I'm dragging a `.docx` onto the pandoc convertor. – rev Aug 24 '12 at 10:43