Capture Results From ⌘F (Find) In A PDF

I’m new to KM and trying to use it to search a pdf file that holds employee names & phone extensions. I’d like to search the PDFPen file for the employee name and capture the found results. Is there a group of commands or AppleScript (trying to learn some of that too) to capture the results into a variable of a ⌘F keystroke (Find) that can then be parsed to get the extension and speak the extension as text?

Any suggestions would be truly appreciated.

This AppleScript gets the value of field 2 of every row in the found-items table in the Find window.

tell application "System Events"
  tell application process "PDFpenPro"
    set frontmost to true
    tell window "Find"
      set foundList to value of text field 2 of rows of table 1 of scroll area 1 of splitter group 1
    end tell
  end tell
end tell

It’s a kludgy way of going about things, but it works.

-Chris

I’m curious to know a couple of things.

A) Is your PDF file an in-house list or a public one. If public I’d like a copy to test with. I can be reached here: listmeister@thestoneforge.com.

B) Are you always doing lookups in the same file?

C) Which OSX are you running?

There may be a more efficient way of going about this.

-Chris

Thanks Chris!

The PDF file is an in-house list that I always use to look up the four-digit extension of other employees. I’m running OS X Yosemite v10.10.5. I’m new to the company so I’m often pulling out the list from my briefcase to look up the numbers. Since trying KM, I decided to attempt to use my computer to find the extensions and have some fun learning.

foundList only has one item in the format: {ExtensionFirstName_LastNameTitlePhoneNumber}, where _ is a space between First & Last Name.

I would like to parse foundList and speak any or all pieces of it with appropriate english syntax (adding any necessary words), but I haven’t figured out how or find a way to convert it to a string. I use “say foundList”, but it just speaks the entire item all together (e.g. 0123JoeSmithDirector(999)999-9999)

Any suggestions?

References For Learning & Using Applescript
Learning & Using AppleScript & JavaScript for Automation (JXA)

I'm not sure there is a good definition of a splitter group anywhere...

GUI-Scripting with System Events is complicated and takes mucho patience to learn.  :smile:

You need Apple's Accessibility Inspector (part of Xcode), or preferably UI Browser ($55.00 U.S – there is a demo.). You need to know a bit about AppleScript, and you need some mentoring.

Either utility is able to highlight UI-Elements in an app, so it's easier to associate the name with the element. The syntax of all the items can get really gnarly though.

I bit my tongue about 10 years ago and bought UI Browser 1.0; it has me hours of time and kept me from pulling my hair out.


The way to get an item out of a list is:

set myItem to item 1 of myList

-Chris

If you're willing and able to install an AppleScript Extension and a small Unix command-line program that transforms PDF-to-Text it's likely we can do a lot better.

Satimage.osax AppleScript Extension.

Xpdf command-line program

Install the x86, Mac version.

-Chris

Chris,

You mentioned PDF-to-Text, but I also have the file as an MS Excel file that I could process for the employee contact information. Would finding the name in an Excel file be easier for obtaining string values? Each aspect of the contact information resides in a separate cell of the row the employee’s name is found in!

I'd say yes, but I'd really need an example worksheet to test with.

-Chris

Chris,

Please see attached corresponding MS Excel & PDF directory files.

No files were uploaded...

I believe the forum will only accept .zip and KM-specific files.

You can drag & drop these into the Forum Editor.

Or you can send to me directly at: listmeister@thestoneforge.com

-Chris

Hey Anthony,

I've done some parsing in this one – both in the shell and with a Keyboard Maestro action.

-Chris


ACME Telephone Number Look-Up v1.1.kmmacros (7.4 KB)

1 Like

Chris,

Again, very helpful! Your macro makes clear the ability to use KM command
with regular expression (which I’ve also been trying to learn for this
macro). I was originally just trying to get the extension using regex, but
found the KM Get Substring command based upon the character position (which
was easy because its always in the first four characters) in the string.

I’ll see if I can capture and set variables to the extension, name and
position title using regular expression.

Thank you,

Hey Anthony,

I've changed this around a bit and added a little error-checking.

The list now is changed so the name is at the front and the telephone extension is at the end.

This facilitates type-select in the choose-from dialog when there is more than 1 item found.

I also changed the field delimiter to tab, so parsing is simpler.

The macro now contains an example of searching a variable with a regular expression for multiple captures.

Enjoy.

-Chris


ACME Telephone Number Look-Up v1.1.kmmacros (10 KB)

Chris,

Great work! It would have only taken me another lifetime to come up with
the regex for this!

Thank you very much,

Anthony