使用的Automator或AppleScript的或两者可以递归为PDF文件 [英] Using Automator or Applescript or both to recursively print documents to PDF

查看:245
本文介绍了使用的Automator或AppleScript的或两者可以递归为PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的一套是一个古老的苹果格式(AppleWorks的)文件(4000+)的。我使用他们需要全部更新为PDF。通过在打开的AppleWorks的文件,并使用系统打印的对话,我可以将它们保存为PDF格式,这是理想的。我与AppleScript的/ Automator的一个完整的要点,但是。

I have a massive set of files (4000+) that are in an old Apple format (Appleworks). My employed needs them all updated to PDF. By opening the documents in Appleworks and using the system print dialogue, I can save them to PDF—this is ideal. I'm a complete nub with Applescript/Automator, however.

使用Python脚本我能够从我的老板的电脑收集所有的AppleWorks文件,并把它们放在一个目录;每个文件都是然后在子目录包含其原始位置.txt文件(其中,最终,我将不得不把它们放回去)。

Using a Python script I was able to gather all the Appleworks files from my bosses computer and put them in a directory; each file is then in a subdirectory with a .txt file containing its original location (where, eventually, I will have to put them back).

我需要的脚本来通过这个庞大的目录递归地移动,让每一个文件既不是文件夹,也没有一个.txt文件,并且它在其原始文件,发现在同一目录中保存为PDF格式的 。即

I need the script to move recursively through this massive directory, getting every file that's neither a folder nor a .txt document, and save it to PDF in the same directory in which the original file was found. ie.

/ AppleWorks的/ Boss_File_1 /

将包含

/Appleworks/Boss_File_1/Boss_file_1.cwk
/Appleworks/Boss_File_1/path.txt

但最终必须也含有 /Appleworks/Boss_File_1/Boss_File_1.pdf

我可以用任何一种解决方案的一半,但不知道如何让他们一起工作。该AppleScript的我使用看起来像:

I can get half way with either solution, but don't know how to make them work together. The Applescript I'm using looks like:

set appleworksFolder to choose folder

tell application "Finder"
set folderItems to (files of entire contents of appleworksFolder)
repeat with I from 1 to number of items in folderItems
    set the_doc to item I of folderItems
    if name of the_doc is not "path.txt" then
        try
            tell application "AppleWorks 6"
                open the_doc
                tell application "System Events"
                    tell process "Appleworks"
                        keystroke "p" using command down
                        click menu button "PDF" of window "Print"
                        click menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"
                        click button "Save" of window "Save"

                    end tell
                end tell
            end tell
        end try
    else
        tell application "Finder"
            delete the_doc
        end tell
    end if
end repeat

结束tell`

end tell`

这将打开打印对话,但从来没有得到任何进一步的,我不知道为什么。我知道这脚本还没有处理把文件放回原来的文件夹,但在AppleScript的,我可以很轻松地做到这一点,如果我能得到过去的实际打印到PDF位。

This opens the print dialogue but never gets any further and I have no idea why. I realize this script also doesn't deal with putting the document back in its original folder, but in Applescript I could easily enough do this if I could get past the actual printing-to-PDF bit.

同时,在Automator中,使用这种工作流程:

Meanwhile, in Automator, using this workflow:

Get Specified Finder Items
Get Folder Contents
Filter Finder Items (by kind and then by file extension is not .txt)
Open Finder Items (with Appleworks)

然后我很卡住;使用实际打印Finder项目并选择的Adobe PDF 似乎实际上什么也不做,和使用打印记录自己为PDF过程中直播是无用的,因为我不知道怎么去的Automator保留文件源于路径,并确保其打印到它。

I then am stuck; using the actual Print Finder Items and choosing Adobe PDF seems to actually do nothing at all, and recording myself using the print to pdf process live is useless because I don't know how to get Automator to retain the path the file originated from and ensure it prints to it.

如果有人能帮助我把这个在一起不知怎么的,我会深深的感激。谢谢你。

If anyone can help me put this together somehow, I'd be enormously grateful. Thanks.

推荐答案

试试这个:

set appleworksFolder to choose folder
set thePath to POSIX path of appleworksFolder as string

tell application "Finder"
set folderItems to files of appleworksFolder
repeat with aFile in folderItems
    set {name:fileName, name extension:nameExtension} to aFile
    set filePath to POSIX path of (aFile as alias) as string

    if nameExtension is not "txt" then
        set theLocation to POSIX path of (aFile as text)
        set baseName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
        set destLocation to (thePath & baseName & ".pdf")
        set theCommand to "/System/Library/Printers/Libraries/./convert -f \"" & filePath & "\"" & " -o " & "\"" & destLocation & "\"" & " -j \"application/pdf\""
        do shell script theCommand

    else
        tell application "Finder" to delete aFile
    end if
end repeat
end tell

这篇关于使用的Automator或AppleScript的或两者可以递归为PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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