简体   繁体   English

将图像保存到同一文件夹的 Automator 快速操作

[英]Automator Quick Action to Save Images into Same Folder

I'm trying to make an Automator Quick action (Mac OS) that will save images from pdf pages into the same folder where the pdf is located .我正在尝试制作一个 Automator Quick action (Mac OS),它将 pdf 页面中的图像保存到 pdf所在的同一文件夹中

**Edit: user3439894 wrote that I should have and did not make totally clear that I want "to send multiple files to the Quick Action from different folders and have the files created in each respective folder the file is in" **编辑:user3439894 写道,我应该并且没有完全清楚我想“将多个文件从不同文件夹发送到快速操作,并在文件所在的每个文件夹中创建文件”

I found that it's easy to have files saved to a particular folder;我发现将文件保存到特定文件夹很容易; for example, here's a workflow that saves images from a pdf to the desktop:例如,这是将图像从 pdf 保存到桌面的工作流程: 在此处输入图片说明

The hard part is saving to the same folder where the pdf is located.困难的部分是保存到 pdf 所在的同一文件夹中。 I tried to adapt this answer , but I get: "Rename Finder Items: Name Single Item" encountered an error: "More than one Finder item was passed to Name Single Item".我试图修改这个答案,但我得到:“重命名 Finder 项目:命名单个项目”遇到错误:“多个 Finder 项目被传递给命名单个项目”。 I don't know how to fix that -- the whole point of my task is to output multiple images from the .pdf.我不知道如何解决这个问题——我的任务的重点是从 .pdf 输出多个图像。

There are actually 2 workflows shown on the stackoverflow page I mentioned above . 我上面提到的 stackoverflow 页面上实际上显示2 个工作流。 I tried adapting both of them and they both gave the same error.我尝试对它们进行调整,但它们都给出了相同的错误。 Below is one of my adaptions.以下是我的改编之一。 The "Get Specified Finder Items" action is just for testing purposes. “获取指定的 Finder 项目”操作仅用于测试目的。 在此处输入图片说明 在此处输入图片说明

This gets a bit convoluted because Automator doesn't have a default action to get names or paths (that was one of my first actions back in the day), you need to shuffle stuff around while you work at getting items into variables, and workflows handle multiple input items as a single batch.这有点令人费解,因为 Automator 没有用于获取名称或路径的默认操作(这是我当天的第一个操作之一),您需要在将项目放入变量和工作流中的同时进行调整将多个输入项目作为一个批次处理。

The Rename Finder Items action will only rename (you need to use the Make Sequential option rather than Name Single Item ), but that doesn't help much, especially since the Render PDF Pages as Images action also uses sequential numbers in its output. Rename Finder Items操作只会重命名(您需要使用Make Sequential选项而不是Name Single Item ),但这并没有多大帮助,特别是因为将PDF 页面渲染为图像操作也在其输出中使用序列号。

For items with the same parent folder (otherwise a third party action would need to be used to handle the items individually), a Run AppleScript action can be used (as in your linked examples) to get the parent folder for use in a variable, so your workflow would be something like:对于具有相同父文件夹的项目(否则需要使用第三方操作来单独处理这些项目),可以使用Run AppleScript操作(如您链接的示例中所示)来获取父文件夹以用于变量,所以你的工作流程是这样的:

  • Workflow receives PDF files in any application工作流在任何应用程序中接收 PDF 文件
  • Set Value of Variable { Variable: input }设置变量值{变量:输入}
  • Run AppleScript:运行 AppleScript:

     on run {input, parameters} tell application "Finder" to return (container of first item of input) as alias end run
  • Set Value of Variable { Variable: folder }设置变量{变量:文件夹}的值
  • Get Value of Variable { Variable: input } (Ignore input)获取变量值 { 变量:输入}(忽略输入)
  • Render PDF Pages as Images将 PDF 页面渲染为图像
  • Copy Finder Items { To: folder } (select or drag folder variable to combobox field) Copy Finder Items { To: folder }(选择或拖动文件夹变量到组合框字段)

I found a way that works for me.我找到了一种适合我的方法。

  • Workflow receives PDF files in any application工作流在任何应用程序中接收 PDF 文件
  • Set Value of Variable {Variable: InputPDFs}设置变量 {Variable: InputPDFs} 的值
  • Run AppleScript:运行 AppleScript:

     on run {InputPDFs, parameters} tell application "Finder" to return (container of first item of InputPDFs) as alias end run
  • Set Value of Variable {Variable: PathToPDFs}设置变量 {Variable: PathToPDFs} 的值

  • Get Value of Variable {Variable: InputPDFs} (Ignore input)获取变量 {Variable: InputPDFs} 的值(忽略输入)
  • Render PDF Pages as Images将 PDF 页面渲染为图像
  • Set Value of Variable {Variable: InputPDFs}设置变量 {Variable: InputPDFs} 的值
  • Get Value of Variable {Variable: InputPDFs} (Ignore input)获取变量 {Variable: InputPDFs} 的值(忽略输入)
  • Rename Finder Items: Make Sequential重命名 Finder 项目:按顺序排列
  • Set Value of Variable {Variable: InputPDFs}设置变量 {Variable: InputPDFs} 的值
  • Move Finder Items {To: PathToPDFs}移动 Finder 项目 {To: PathToPDFs}

The following solution in the screenshot works fine in Catalina (10.15.7).屏幕截图中的以下解决方案在 Catalina (10.15.7) 中运行良好。

  1. It prompts you to select the input PDF (you can replace that with your preferred input method).它会提示您选择输入的 PDF(您可以将其替换为您喜欢的输入法)。
  2. It stores the full path including the input file name ("PDF-file"), the full path excluding the input file name ("pdfPath") and the base input file name without path and extension ("pdf-name").它存储包括输入文件名(“PDF-file”)的完整路径、不包括输入文件名的完整路径(“pdfPath”)和没有路径和扩展名的基本输入文件名(“pdf-name”)。
  3. Renders PDF to images将 PDF 渲染为图像
  4. Renames each image as pdf-name-*** (note: If you skipped renaming or used "Add number to existing item name", you would end up with the automatic indexing added by the Render PDF as images widget which won't start with 01 but rather number-of-pages + 1 eg. 66, 67, 68, etc. if your pdf has 65 pages).将每个图像重命名为 pdf-name-***(注意:如果您跳过重命名或使用“将编号添加到现有项目名称”,您最终会得到 Render PDF as图像小部件添加的自动索引,该小部件不会启动如果您的 pdf 有 65 页,则为 01,而是页数 + 1,例如 66、67、68 等)。
  5. Save images to the original input folder (same folder where the selected PDF is located).将图像保存到原始输入文件夹(所选 PDF 所在的文件夹)。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM