【问题标题】:AppleScript/Automator: renaming PDF with extracted text content of this PDFAppleScript/Automator:使用此 PDF 的提取文本内容重命名 PDF
【发布时间】:2020-11-13 08:22:45
【问题描述】:

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

PDF 的整个文本被提取到桌面“PDF2TXT.rtf”(= 变量 theFileContents)上的新(临时)文件中,使用 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”。

很高兴提出任何建议。提前致谢。

q3player

【问题讨论】:

    标签: pdf applescript file-rename


    【解决方案1】:

    试试这个:

    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
    

    【讨论】:

      猜你喜欢
      • 2014-09-11
      • 2018-06-23
      • 1970-01-01
      • 2013-02-05
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多