Keyboard Maestro “Convert PDF Files into Text Files in the Front Finder Window” Macro

So I tried the macro and nothing happens. When you say finder window, do I open the pdf in the front finder window or do I open the folder where the file is and select it? Neither seems to work.

Ok, never mind. It was added to the test group which was disabled. I got it to run.
I have a text file. It looks really good. I did get an error:

Shell Script
errorText:
xargs: unterminated quote

But since I have the text I need this will work.

Hey John,

This doesn't happen to me.

Send me a pic of the window you're running the macro on, so I can try to recreate the problem.

-Chris

Hey John,

Here's how to get the text of a single selected PDF file in the Finder into BBEdit.

** REQUIRES ** the same command line tool as the macro above.

-Chris


Finder -- Send Text of Selected PDF File to BBEdit.kmmacros (6.5 KB)

A couple of questions. Can I install v. 4.00 over my v. 3.04 version?

The install instructions say to copy xpdf, pdftotext, etc to /usr/local/bin I assume I can do:

cp /Users/zz/Downloads/xpdf-tools-mac-4.00/bin64/pdfdetach /usr/local/bin

Could I just do:

cp /Users/zz/Downloads/xpdf-tools-mac-4.00/bin64/* /usr/local/bin

I also seem to remember I had to do something to get it into my shell.

Hey John,

You don't need cp at all.

Just open a Finder window, type Cmd-Shift-G, and paste in the path you want to go to:

/usr/local/bin
/usr/local/man/man5

Then drag the requisite files into the correct folder.

The Finder will make you authenticate the action, but that's it.

Once you've copied the files you're good to go – UNLESS /usr/local/bin/is NOT in your $PATH.

You should not have a problem if pdftotext v3.0.4 was working for your, but if you do you can see this thread:

Create a PATH Environment Variable for Keyboard Maestro and Add /usr/local/bin to the Default Path

-Chris

I copied 4.0 version successfully, Thanks!

I put it into /usr/local/bin however the man folder appears to be missing from 'local'. Can I just create the folder(s)? (man, man5)

I am also wondering why it would be missing since I am obviously using man with other applications.

Hey John,

This sort of thing is easy enough to test yourself, but yes you can create those folders.

Because /usr/local/bin is a directory for USER-installed executables.

-Chris

Great tool!

1 Like

The script makes a txt file of every pdf in the current folder.
I would like to put the text of a (all) selected pdf file(s) into a KM variable.

How would the macro look like then? I know how to give the shell script a single file instead of a folder, but the shell script is expecting a folder and returns an error if i give it a single file instead.
How can i change this?

Hey @ccstone

A useful tool. Thank you very much for making it available!

1 Like

Thank you @ccstone for this.
Works perfectly!


I am a beginner with Keyboard Maestro, and while I can work the basic stuff, I don't really understand Apple Script / Shell Script (yet).

How can I modify the original KM Macro to save the results to a variable, rather than to a new text file?

I hope to parse some details out of the PDF, and use it to rename the PDF itself. I don't need the data for anything else.

Thank you.

Hey @Sinizter,

Read the last part of Post #1.

If you're still scratching your head let me know.

-Chris

@ccstone

Thank you.

I was scratching my head... But, I went and worked out what xargs was and what it was doing in this script, and read the documentation of xpdfreader and now what you posted makes complete sense.

I am going to try and make something that takes all selected PDFs from Finder window and rename them to my preferred naming convention based on contents.

1 Like

I'm scratching my head over this whole thing! I have done as directed, but am getting this error stream and nothing else:

Shell Script

errorText:

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/cyrillic/Bulgarian.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/greek/Greek.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/thai/Thai.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/cyrillic/Bulgarian.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/greek/Greek.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/thai/Thai.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/cyrillic/Bulgarian.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/greek/Greek.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/thai/Thai.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/cyrillic/Bulgarian.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/greek/Greek.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/thai/Thai.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/cyrillic/Bulgarian.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/greek/Greek.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/thai/Thai.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/cyrillic/Bulgarian.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/greek/Greek.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/thai/Thai.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/cyrillic/Bulgarian.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/greek/Greek.nameToUnicode'

Config Error: Couldn't open 'nameToUnicode' file '/Users/wendydunning/xpdf/thai/Thai.nameToUnicode'

xargs: unterminated quote
Any and all suggestions would be welcome to this newbie!

Hey Wendy,

What macro are you running?

What happens if you open the Terminal and run:

pdftotext -v

-Chris

Hey Chris,

Using [or trying to] "Convert PDF Files into Text Files in the Front Finder Window"
I got the BBEdit one to work for a single file-but can't get the original to work at all. Followed the Cmd+Shift+G to get to where I was supposed to put the files, although the 'install' doc that comes with them says it's not necessary? I even tried putting the language files in there as well, but the same error appears.
Thanks for the uber swift reply BTW

BTW this is what I get after typing your suggestion in terminal:

pdftotext version 4.03 [www.xpdfreader.com]

Copyright 1996-2021 Glyph & Cog, LLC

Wendys-iMac:~ wendydunning$

I don't think that version is on there anymore.

Anyways I got it to work, really cool software and script, so thank you.

FOR CURRENT INSTALLATION USE HOME BREW (link: xpdf — Homebrew Formulae)

All you have to do is open a new terminal type in the command below and then press enter

$ brew install xpdf

You would be mistaken – version 4.0.3 is on the Download page:

Mac 64-bit: download

You're welcome.  :sunglasses:

There's nothing wrong with Hombrew, but keep in mind that it doesn't come stock on macOS and must be installed by the user.

-Chris

1 Like