自动器“复制查找器对象"与AppleScript [英] Automator "copy finder object" with AppleScript

查看:69
本文介绍了自动器“复制查找器对象"与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 screenshot

推荐答案

按照原始脚本进行操作,该脚本似乎想将所有文件移动到用户的主文件夹中,因此可以使用automator变量完成所需的操作.首先,转到自动器"窗口的左上角,单击显示变量"的选项卡按钮,然后单击位置"项.查找显示"Home"(我的机器语言为"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)操作上,并将其放在"To:"("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:

应该可以解决问题.

您可以选择各种系统定义的用户路径.您还可以使用特殊的文本"变量(在文本和数据"下)定义自定义变量,并以标准unix表示法键入路径,其中波浪号(〜)表示用户的主文件夹:例如,〜/path/to/自定义文件夹/.

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 变量中的动作作为别名列表,无论您 return (应该是别名或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...

将以下操作添加到问题中给出的工作流中,以代替复制查找器对象".行动.请注意,第二和第六个操作设置为忽略上一个操作的输入.这些操作将执行以下操作:

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,该AppleScript从输入列表构造一个unix路径字符串;将完成的路径字符串传递给下一个动作
  5. 将路径字符串保存到名为"DestinationFolder"的变量中;不传递任何数据
  6. 检索我们在步骤1中保存的要复制文件的列表;将其传递给下一个动作
  7. 使用我们在步骤5中保存的"DestinationFolder"变量将文件复制到所选文件夹;将这些信息传递给重命名查找器项"操作(此处未显示)

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

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

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

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