Form Input/File Renaming Help

Hi all,
I'm stuck. I'm hoping to learn from this and hoping some of you can point me in the right direction/resources.

I'm looking to rename files in a specific folder, possibly using a form input system. I'm essentially trying to keep files organized in a cataloging system.

I download a LOT of PDFs from online archival resources and they are always poorly named. I'm thinking about setting up an input prompt where I input variables. Example:

Publication Name: _____
Year: ____
Volume: ______
Issue: _____

I want to:

  1. rename the files based on these variables;
  2. Be able to apply this to multiple files (at least keeping the First 3 Variables the same with the option of entering a new variable for the last.

I'm wondering if there is a specific way to store previously inputted data to the form. And then perhaps apply this to the entire batch I've downloaded so that they have the same file name with the exception of changing volumes or issues.

I'm really eager to learn more macros. Any resources to help with this specific task or any prerequisite reading before attempting this is welcomed and much appreciated.

Thanks!

Maybe a stupid question, but have you done a forum search for “renaming files” or such?

If you are speaking of PDF forms, this can only be addressed via PDF programs (you cannot write to the source data). The PDF program can be scripted though (depending on the program).

Uhps, got it now:

This is pretty simple:

  • Assuming all the PDFs have the correct meta data
  • Extract the meta data (there are various command line tools or GUI tools for that) and feed them to KM
  • Tell the KM macro to rename the file according to the right piece of the extracted data

So, all in all, it should be possible. But more infos needed. :wink:


PS:

Welcome to the forum!

Didn’t mean to be harsh. Just me. Or the day. :slight_smile:

Thanks,

I'm a bit stuck. The metadata from these files is lacking, hence my need to input data manually. These are documents that have been scanned from the 70s and the curators have not created a nice file naming system.

To clarify, I'm just trying to implement a simple file renaming system that can help me catalog files. This (attached) macro looked like a promising baseline. It prompts you to fill in fields and then will move the file..I think.

I cannot for the life of me figure out why I cannot get it to work. It does not even get past the %TriggerValue% split path action.

Any ideas how to move forward?

Again my goal is pretty simple I think. Import a PDF into a folder (filename: xyz123456.pdf) and then I want to change such file name to include the publication, year, volume, issue data that I input from a prompt. E.g:

Import: xyz123456.pdf

Prompt: Rename File
Variable: Publication Name- KMJournal
Variable:Year- 2020
Variable: Volume: 2
Variable: Issue- 1

New filename: KMJournal_2020_Vol2_1.pdf. Something like that.

Assuming you've selected files in the Finder, you might try this approach instead:

ss-288

You above post and the example macro you showed later are not completely consistent, so I am having to guess at what you actually want.

Here is an EXAMPLE macro to help get you started.
It is triggered by adding/dropping a new file into your Downloads folder, and then prompts you for the fields you listed above.
Of course, you can change any/all of this.
You should carefully review the Actions in magenta color, like the one below to ensure they have the values/settings you want:
image

In particular, review this Action which set the new name of the file using your input metadata:
image
%Local__DestinationFolder%/%Variable%DND_RDF__Pub_Name% %Variable%DND_RDF__Year% %Variable%DND_RDF__Volume% %Variable%DND_RDF__Issue%.%Local__Ext%

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Example Output

MACRO:   Rename Downloaded File Using Prompt for Metadata [Example]

-~~~ VER: 1.0    2020-03-27 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Rename Downloaded File Using Prompt for Metadata [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
==This macro also has a preset trigger to execute when a file is added to your Downloads folder.==


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Rename Downloaded File Using Prompt for Metadata

NOTICE: This macro/script is just an Example

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

REQUIRES:

  1. KM 8.0.2+
  • But it can be written in KM 7.3.1+
  • It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
    .
  1. macOS 10.11.6 (El Capitan)
  • KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees. :wink:

==MACRO SETUP==

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
      .
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    • ALL Actions that are shown in the magenta color
      • Set Variable “Local__DestinationFolder”
      • Prompt for User Input
      • Set FULL Path for Renamed File

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

Thank you! this is excellent and super helpful. Can I ask what do the prefix DND_RDF_ refer to?

1 Like

Yep, it's my standard KM Variable naming convention for Global Variables:

  • "DND" -- means "Do Not Delete" so when you look at all of the KM variables in the Variable panel, you know NOT to delete variables that have this prefix.
  • "RDF" -- a 3-char prefix for the specific macro (or macro set) that this variable belongs to. In this case it is "Rename Downloaded File". This is to handle common cases like "FilePath" that might be needed in many different macros, but you don't want one to overwrite the other. So, "DND_RDF__FilePath" makes for a likely unique name.
  • "__" -- two underscores after that so that all of the prefix does NOT appear in the Prompt Action.

This has worked well for me for a long time, but each user should choose a naming convention that works best for them.