AppleScript/Automator:使用此 PDF 的提取文本内容重命名 PDF [英] AppleScript/Automator: renaming PDF with extracted text content of this PDF

查看:27
本文介绍了AppleScript/Automator:使用此 PDF 的提取文本内容重命名 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

PDF 格式的整个文本被提取到桌面上的一个新(临时)文件PDF2TXT.rtf";(= 变量 theFileContents),使用 Automator 操作完成以从 PDF 中提取文本.

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

我现在需要做的就是将输入的 PDF 重命名为myProjectNo".

What I need now is the rest to rename the input PDF to "myProjectNo".

很高兴收到任何建议.提前致谢.

Happy for any suggestion. Thanks in advance.

q3player

推荐答案

试试这个:

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

保存为 droplet 的脚本(= 应用程序):

the script to save as droplet (= application) :

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

这篇关于AppleScript/Automator:使用此 PDF 的提取文本内容重命名 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆