【问题标题】:How can I create a display dialog that presents specific file path options for a given PDF file?如何创建一个显示对话框来显示给定 PDF 文件的特定文件路径选项?
【发布时间】:2013-12-04 02:35:40
【问题描述】:

我对使用 Automator 和 Applescript 非常陌生。

我想使用 Automator 和 AppleScript 来检测下载到“下载”文件夹的 PDF 文件,并打开一个显示对话框,让我可以选择文件路径和移动文件。到目前为止,我所拥有的(这是不对的)是这样的:

set question to display dialog "Save fileName in..." buttons {"Figuring Relation", "Iconoclasm", "Elsewhere"} default button 3

set answer to button returned of question

    if answer is equal to "Figuring Relation" then
        tell application "Finder" to move fileName to POSIX file "/Users/mac/Documents/College/Junior/Fall/Art 347 - Figuring Relation"

我希望“计算关系”和“Iconoclasm”按钮将文件路径更改为指定的文件路径(我不想浏览它),并希望“其他地方”按钮打开一个 Finder 窗口,我可以选择/浏览路径。

如果可能,我还希望将日期添加到文件名的开头作为“mm-dd_filename”。

我不确定如何将 Automator 输入转换为 Applescript,或者如何在显示对话框文本中包含文件名。非常感谢您的帮助。

【问题讨论】:

  • AppleScript-Editor 中包含的 code-sn-ps 总是有帮助的:CTRL-单击脚本以查看它们。查看“迭代项目”,您会在其中找到一些有用的代码。

标签: pdf applescript filepath automator


【解决方案1】:

这是一个仅使用 applescript 的示例。在我的示例中,它假设您正在选择要移动的文件,但是如果您愿意,您可以轻松地为脚本添加一些内容以“查找”所有以“.pdf”结尾的文件,然后遍历结果.

on run
    try
        set thisFile to choose file
        tell application "Finder" to set currentName to thisFile's name

        -- Setting variables for the destinations to be used later
        set FiguringRelationPath to (path to documents folder) & "College:Junior:Fall:Art 347 - Figuring Relation:" as string
        set IconoclasmPath to (path to documents folder) & "Iconoclasm:" as string

        -- Ask the user
        set answer to button returned of (display dialog "Save \"" & currentName & "\" in..." buttons {"Figuring Relation", "Iconoclasm", "Elsewhere"} default button 3)

        -- Set the destination variable based on the users response to the dialog
        if answer is equal to "Figuring Relation" then
            set destination to FiguringRelationPath
        else if answer is equal to "Iconoclasm" then
            set destination to IconoclasmPath
        else
            set destination to choose folder with prompt "Please select the destination folder" as string
        end if

        -- Test that the destination directory exists, if not post the error
        try
            set destination to destination as alias
        on error
            error ("Destination path " & destination as string) & " doesn't appear to exist"
        end try

        -- Rename the file with the date prefix
        set tDatePrefix to (do shell script "date '+%m-%d'") & "_" as string
        tell application "Finder" to set x's name to tDatePrefix & x's name as string

        -- Move the file
        tell application "Finder" to move thisFile to destination

    on error err
        activate
        display dialog "Error: " & err buttons {"OK"} default button 1
    end try
end run

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    相关资源
    最近更新 更多