Page 1 of 1
Use text inside document to rename a file

Posted:
Wed Jun 09, 2010 7:12 pm
by smithjw
Hi guys, I was wondering if there is an easy way to rename a file based on text that is contained within the document its self.
The scenario is:
I'm using automator to create a print plugin that creates a PDF in a specific document.
What I need Hazel to do:
When that file is created there is a title up the top saying "Invoice 3333", now I want hazel to look for that "Invoice 3333" and rename it based on the number there. BTW this number changes every time a new PDF is created.
If anyone can help I'd be in your debt.
Cheers
Re: Use text inside document to rename a file

Posted:
Mon Jun 14, 2010 3:53 pm
by Mr_Noodle
The only way to do this now is via a script. If you're not adept at scripting yourself then either someone here might be able to throw something together or maybe check some AppleScript forums out there for help.
Re: Use text inside document to rename a file

Posted:
Mon Jun 14, 2010 5:13 pm
by alastor933
Paul:
When creating a condition in a rule, the first popup has "contents".
Is that not "file contents"?
I played with it, a few days ago, and subsequently found a handful of PDFs that had been in the watched folder, but were moved, apparently because they contained the specific word I put in the condition "Contents contain <the word>.
So I assumed it is file content, not folder content.
smithjw:
Getting an unknown term is another matter; this can only be done when you know exactly where it is.
"Up the top" does not qualify as such, you need to be very precise: say 'the first and second word of the first line'.
But AppleScript cannot read PDF, only plain text (extension .txt).
Is there another place where a script could get that 'Invoice xxxx'?
Does your Automator plugin get it from elsewhere, or is it calculated by the plugin?
Why can't the plugin do the renaming?
Where's the name coming from, anyway?
And, finally: did you create the plugin, or is it a black box to you?
Yes, a bunch of questions. But relevant ones, I think...
Re: Use text inside document to rename a file

Posted:
Tue Jun 15, 2010 1:34 pm
by Mr_Noodle
Yes, contents means file contents but it's limited to text that Spotlight indexes and right now can only do exact matches.
One thing that did come to mind is if this text appears in other metadata. Like either as the title or in the keywords. You'd have to poke around (you can use the 'mdls' command if you want to dump out all the metadata) and see. If it's there, then you can use Hazel's pattern matching in that case.
Re: Use text inside document to rename a file

Posted:
Sat Mar 19, 2011 1:05 pm
by Lusule
I know that if you have a Fujitsu Scansnap, the software can recognise highlighter marks on the original paper. There is an option that takes highlighted text and turns it into a keyword. The keyword is then flagged and I believe can be used in Hazel so you could possibly achieve your goal by manually highlighting the invoice number before scanning it if you had this software. It's possible there's other software as well that does the same thing, or that the Scansnap uses 3rd party software that can be obtained separately.