0

我创建了两个液滴,一个用于重命名文件,另一个用于打印文件。它们比这更复杂,但这就是本质。有时我们只需要重命名它们,有时只需要打印它们,有时两者都做。由于每个用户都需要进行广泛的定制,我更愿意将两个液滴分开。

所需的工作流程:将文件拖动到 RenameMe 液滴,如果按住命令键,则将重命名的文件传递给 PrintMe 液滴。

在 checkModifierKeys 脚本的帮助下(对不起,手边没有引用),我可以检查是否按下了命令键,以便处理脚本的一部分。问题是如何从第一个液滴触发第二个液滴。我尝试使用第二个 droplet 作为应用程序打开文件(如下面的代码所示),但出现通信错误。

有任何想法吗?——亚历克斯

示例代码:

on open the_Droppings
set flPth to POSIX path of (path to me) & "Contents/MacOS/checkModifierKeys"
set cmdPressed to (do shell script (quoted form of flPth & " command")) as integer as boolean

repeat with i from 1 to (count of items in the_Droppings)
    set file_name to "NEW NAME FROM SCRIPT" #actual script that generates name isn't relevant
    tell application "Finder"
        set name of file (item i of the_Droppings) to file_name
    end tell

    if cmdPressed is true then
        #pass the file to the PrintMe droplet       
        tell application "PrintMe"
            open (item i of the_Droppings)
        end tell
    end if
end repeat
end open
4

1 回答 1

0

您可以向 PrintMe 添加显式运行处理程序,这将允许您进入脚本的两个不同入口点。两者都需要争论。我在这里设置了一个文件,将一个文件传递给运行处理程序,并将一个列表传递给打开处理程序,但如果你愿意,你可以将一个列表传递给运行处理程序,并重复你在 open 中所做的相同方式。

在重命名我:

if cmdPressed is true then
    #pass the file to the PrintMe droplet       
    run script (load script file "path:to:PrintMe.app") with parameters (item i of the_Droppings)
end if

在打印我:

on open the_droppings
    repeat with i from 1 to (count the_droppings)
        process(item i of the_droppings)
    end repeat
end open

on run the_file
    process(the_file)
end run

on process(the_file)
    // Code for printing files goes here
end process
于 2013-08-29T19:11:35.607 回答