简体   繁体   中英

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 .

**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"

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: 在此处输入图片说明

The hard part is saving to the same folder where the pdf is located. 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". I don't know how to fix that -- the whole point of my task is to output multiple images from the .pdf.

There are actually 2 workflows shown on the stackoverflow page I mentioned above . 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. 在此处输入图片说明 在此处输入图片说明

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.

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.

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:

  • Workflow receives PDF files in any application
  • Set Value of Variable { Variable: input }
  • Run 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
  • Copy Finder Items { To: folder } (select or drag folder variable to combobox field)

I found a way that works for me.

  • Workflow receives PDF files in any application
  • Set Value of Variable {Variable: InputPDFs}
  • Run 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}

  • Get Value of Variable {Variable: InputPDFs} (Ignore input)
  • Render PDF Pages as Images
  • Set Value of Variable {Variable: InputPDFs}
  • Get Value of Variable {Variable: InputPDFs} (Ignore input)
  • Rename Finder Items: Make Sequential
  • Set Value of Variable {Variable: InputPDFs}
  • Move Finder Items {To: PathToPDFs}

The following solution in the screenshot works fine in Catalina (10.15.7).

  1. It prompts you to select the input PDF (you can replace that with your preferred input method).
  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").
  3. Renders PDF to images
  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).
  5. Save images to the original input folder (same folder where the selected PDF is located).

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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