【问题标题】:Applescript Droplet to Droplet CommunicationApplescript Droplet 到 Droplet 的通信
【发布时间】:2013-08-31 05:51:07
【问题描述】:

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

所需的工作流程:将文件拖动到 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

【问题讨论】:

  • 为什么不在 RenameMe 脚本应用程序包中保留另一个脚本的别名(甚至是副本),然后每次都调用它?
  • 这是相同的工作流程@MondoJobsNY was tweeting this morning吗?

标签: applescript


【解决方案1】:

您可以向 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

【讨论】:

  • 谢谢 Josh,但 PrintMe 脚本是为每个用户定制的,所以每次更新 RenameMe 时,我都无法轻松地重新部署它作为 RenameMe budle 的一部分。
  • 谢谢达里克,这可能有用。用户在同一个目录下有 RenameMe 和 PrintMe,所以我可以很容易地找到 PrintMe 的路径。我试试看。
  • 感谢 Darrick,只需在运行语句后添加“脚本”即可编译,它就成功了。
猜你喜欢
  • 2017-02-03
  • 1970-01-01
  • 1970-01-01
  • 2021-08-22
  • 1970-01-01
  • 1970-01-01
  • 2020-04-10
  • 2018-07-23
  • 1970-01-01
相关资源
最近更新 更多