AppleScript/Automator:使用此PDF的提取文本内容重命名PDF



我有很多想要重命名的PDF。新名称应该是此PDF的文本项。我不想把它创建为一个文件夹操作,将PDF放入并重命名。到目前为止,我已经使用Automator和AppleScript:

PDF的整个文本被提取到桌面上的一个新的(临时(文件";PDF2TXT.rtf";(=变量FileContents(,使用Automator操作从PDF中提取文本。

下面是将新名称从文本中分离出来的代码:

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

我现在需要的是将输入的PDF重命名为";myProjectNo";。

很乐意接受任何建议。提前谢谢。

q3层

试试这个:

tell application "Finder" to set name of foo to bar

保存为液滴的脚本(=应用程序(:

on run -- you can run the applet it will prompt for files
open {choose file of type "pdf"}
end run
on open (thesefiles) -- you cn drop files on this applet
repeat with theFileContents in thesefiles
-- set od to AppleScript's text item delimiters -- duplicate : same as oldDelimiters
set theFileContentsText to read theFileContents as text
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "Projectno. "
set theArray to last text item of theFileContentsText
set AppleScript's text item delimiters to space
set myProjectNo to first text item of theArray
-- return myProjectNo -- and never come back again ;-)
set AppleScript's text item delimiters to oldDelimiters -- this can't go after the return ( = never called)…
set newPDFname to "Project No" & space & myProjectNo & ".pdf"
tell application "Finder"
display dialog "You really want to renamme this file to " & return & newPDFname & " ?"
set the name of thisFile to newPDFname
end tell
end repeat
end open

最新更新