I have a lot of PDFs that I want to rename. The new name should be a text item of this PDF. I wan t to create this as a folder action to drop PDF in and get them renamed. I've com so far with Automator and AppleScript:
The whole text form the PDF is extracted to a new (temporary) file on desktop "PDF2TXT.rtf" (= variable theFileContents), done with the Automator action to extract text from PDF.
Here comes the code that separates the new name out of this text:
on run {theFileContents}
set od to AppleScript's text item delimiters
set theFileContentsText to read theFileContents as text
set myProjectNo to ""
set theDelimiter to "Projectno. "
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theArray to last text item of theFileContentsText
set theDelimiter to " "
set AppleScript's text item delimiters to theDelimiter
set myProjectNo to first text item of theArray
return myProjectNo
set AppleScript's text item delimiters to oldDelimiters
end run
What I need now is the rest to rename the input PDF to "myProjectNo".
Happy for any suggestion. Thanks in advance.
q3player
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…