2013-08-29 55 views
0

我已经创建了两个液滴,一个用于重命名文件,另一个用于打印文件。它们比这更复杂,但这是本质。有时候我们需要重新命名它们,有时候只是将它们打印出来,有时候也会这样做。由于每个用户需要大量定制,因此我希望保持两个水滴分离。Applescript滴到液滴通信

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

在checkModifierKeys脚本的帮助下(很抱歉,没有引用方便)我可以检查命令键是否被按下,以便部分脚本被照顾。问题是如何从第一滴触发第二滴。我已经尝试用第二个液滴作为应用程序打开文件(如下面的代码所示),但得到通信错误。

任何想法? --Alex

示例代码:

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 
+0

你为什么不保持一个别名(甚至是复制)在RenameMe脚本程序包中的其他脚本,然后每次都打电话吗? – scohe001

+0

这是相同的工作流程[@MondoJobsNY今天早上在发送推文](https://twitter.com/mondojobsny/status/373038063523360768)? – adayzdone

回答

0

您可以添加一个明确的运行处理程序PrintMe,这将使你们两个不同的入口点到脚本。两者都有争议。我在这里设置了一个文件传递给运行处理程序,并将一个列表传递给打开的处理程序,但是如果你想要的话,你可以将一个列表传递给运行处理程序,并以与打开时相同的方式重复。

在RenameMe:

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 
+0

感谢Josh,但是PrintMe脚本为每个用户量身定制,因此每次RenameMe更新时,我都无法轻松地将其重新部署为RenameMe的一部分。 – inaneAlex

+0

感谢Darrick,这可能会起作用。用户在同一目录中有RenameMe和PrintMe,所以我可以很容易地找到PrintMe的路径。我会试一试。 – inaneAlex

+0

感谢Darrick,只是在运行语句后添加了“脚本”以便进行编译,并且它实现了诀窍。 – inaneAlex