Automator“复制查找器对象"使用 AppleScript [英] Automator "copy finder object" with AppleScript

查看:25
本文介绍了Automator“复制查找器对象"使用 AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 Apple Automator 服务

I have created an Apple Automator service that

  • 接收 PDF
  • 加密它们
  • 将加密的 PDF 复制到目标文件夹
  • 重命名加密的 PDF

这些都是来自 Automator 的命令.但是,作为Automator命令的复制只能复制到预先定义的文件夹中.

These are all commands from the Automator. However, the copying as an Automator command can only copy to a pre-defined folder.

我想通过 AppleScript 控制这部分,它读出用户名并相应地选择一个文件夹:

I would like to control this part by an AppleScript which reads out the user name and selects a folder accordingly:

on run {input, parameters}
    
    set user_script to "echo $USER"
    set username to do shell script user_script
    
    if username = "A" then
        set standardpfad to "/Users/" & username & "/whatever"
    else if username = "B" then
        set standardpfad to "/Users/" & username & "/foo"
    else
        display dialog "I don't know this user!" with title "ERROR" buttons {"OK"} default button "OK"
        return
    end if
    
    #actual copying
                
end run

不幸的是,我不知道如何以类似于Copy Finder 对象"的方式处理输入.Automator 中的命令.有人可以帮我吗?

Unfortunately, I don't know how to handle the input in way that it resembles the "Copy Finder object" command in Automator. Can anyone please help me?

谢谢!

自动机截图

推荐答案

按照您的原始脚本,它似乎想要将所有文件移动到用户的主文件夹,您可以使用 automator 变量完成您想要的操作.首先,转到 Automator 窗口的左上角,单击变量"选项卡按钮,然后单击位置"项.查找显示主页"的项目(我相信在您的机器语言上是Privat"):

Going by your original script, which seems to want to move all the files to the user's home folder, you can accomplish what you want using an automator variable. First, go to the upper left of the Automator window, click on the tab button that says 'Variables', then click on the 'Locations' item. Look for the item that says 'Home' (I believe that's 'Privat' on your machine's language):

这提供了用户主文件夹的路径,无论哪个用户正在运行工作流(独立于系统和机器).将此变量拖到 Copy Finder Items (Finder-objekte kopieren) 操作上,并将其放在收件人:"(Nach:") 下拉菜单上.它应该是这样的:

This provides to a path to the user's home folder, for whichever user is running the workflow (system and machine independent). Drag this variable over to the Copy Finder Items (Finder-objekte kopieren) action, and drop it on the 'To:' ('Nach:') pull-down menu. It should look like this:

这应该可以解决问题.

您可以选择多种系统定义的用户路径.您还可以使用特殊的Text"变量(在Text & Data"下)定义自定义变量,以标准 unix 表示法键入路径,其中波浪号 ('~') 代表用户的主文件夹:例如,~/path/to/Custom Folder/.

There are an assortment of system defined user paths you can choose from. You can also define a custom one using the special 'Text' variable (under 'Text & Data'), typing a path in standard unix notation where the tilde ('~') represents the user's home folder: e.g., ~/path/to/Custom Folder/.

如果您正在做一些更复杂的事情,并且真的需要使用 Run AppleScript 操作,那么您只需要知道文件列表被传递到input 变量中的操作作为别名列表,并且您返回 的任何内容(应该是别名列表或 posix 路径),都将传递到下一个操作.例如:

If you're doing something more complicated and really need to use a Run AppleScript action, all you need to know is that the list of files is passed into the action in the input variable as a list of aliases, and whatever you return (should be a list of aliases or posix paths), will be passed on to the next action. For example:

on run {input, parameters}
    set output to {}
    repeat with this_item in input
        set new_item to this_item -- ... obviously you'd do something other than just copy
        copy new_item to end of output
    end repeat
    
    return output
end run

但在这里您似乎不需要这样做;特殊的 Automator 变量应该可以帮助您到达目的地.

But it doesn't seem like you need to do that here; the special Automator variables should get you where you're going.

编辑

根据评论,这是工作流程的修订版...

Per comments, here's a revised version of the workflow...

将以下操作添加到问题中给出的工作流程中,以代替Copy Finder Objects"行动.请注意,第二个和第六个操作设置为忽略来自前一个操作的输入.这些操作执行以下操作:

Add the following actions to the workflow given in the question in place of the "Copy Finder Objects" action. Note that the second and sixth actions are set to ignore input from the previous action. These actions do the following:

  1. 将要复制的文件列表保存到名为FileToCopy"的存储变量中;不传递数据
  2. 获取用户主文件夹的路径;传递给下一个动作
  3. 获取用户的'用户名';将主文件夹和用户名作为列表传递给下一个操作
  4. 运行一个 AppleScript,从输入列表构造一个 unix 路径字符串;将完成的路径字符串传递给下一个操作
  5. 将路径字符串保存到名为DestinationFolder"的变量中;不传递数据
  6. 检索我们在步骤 1 中保存的要复制的文件列表;传递给下一个动作
  7. 使用我们在第 5 步中保存的DestinationFolder"变量将文件复制到选定的文件夹;将这些传递给 Rename Finder Items 操作(此处未显示)

试一试,让我知道它是如何工作的.

Give it a go, and let me know how it works.

这篇关于Automator“复制查找器对象"使用 AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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