Help searching a PDF and renaming the file based on PDF content

Hey guys,

I’m struggling getting anywhere with this one and would love to know if its possible.

Basically I have a ton of E-tickets (Madonna, Lakers, Yankees, etc…) and they are sent to me in a crazy file name: ajnfasjknfajkfaf.pdf for example.

Right now I manually go through and change the name to Yankees Red Sox 5/1/12 121 5 3-5.pdf for example.

I was hoping to find a way to automatically do this. So far I have tried pdfminer with Python, Hazel, and any automator’s and none can 100% do what I am looking for.

I found this thread through the search here: https://discussions.apple.com/message/18243084#18243084

It seems to have worked for that guy, but I am sort of a n00b still writing applescript.

Any help is greatly appreciated.

You may download the free Skim.app
http://skim-app.sourceforge.net/
and use this simple script as a starting point.


--[SCRIPT text from PDF]
(*
Yvan KOENIG (VALLAURIS, France)
2012/05/01
*)

choose file of type {"com.adobe.pdf"}
tell application "Skim"
	open result
	set theText to text of document 1
end tell

set tempFile to (path to temporary items as text) & "wasInPDF.txt"

my writeTo(tempFile, theText, text, false)

tell application "TextEdit" to open tempFile as alias

--=====
(*
Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861
*)
on writeTo(targetFile, theData, dataType, apendData)
	-- targetFile is the path to the file you want to write
	-- theData is the data you want in the file.
	-- dataType is the data type of theData and it can be text, list, record etc.
	-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
	try
		set targetFile to targetFile as text
		set openFile to open for access file targetFile with write permission
		if not apendData then set eof of openFile to 0
		write theData to openFile starting at eof as dataType
		close access openFile
		return true
	on error
		try
			close access file targetFile
		end try
		return false
	end try
end writeTo

--=====
--[/SCRIPT]

As I have no idea about the structure of the embedded text, I can’t help you more.

Yvan KOENIG (VALLAURIS, France) mardi 1 mai 2012 21:20:20

Thanks. Its a start!