Get Count of Files in Folder [Example]

Use Case

  • Use when you need a count of ONLY files in a Folder.
  • The Default is the Folder selected in the Finder; If not selected, Then the Target Folder of the Finder's Front Window is used.
  • A Prompt is shown to Confirm/Change Folder Path, and an option to Choose from List
  • This Macro is for Demo purposes. The actual core KM Action is just one Action:
    image
  • Which is very reusable, since the script does not need to be changed to use different KM Variables for input/output.
  • This Macro also provides some reusable techniques for:
    • Get Finder Folder selected
    • Choose Folder from List
    • Branching on Custom Button in Prompt

As always, please feel free to post any comments, issues, and/or suggestions you may have concerning this macro.


MACRO:   Get Count of Files in Folder [Example]

~~~ VER: 1.1    2018-07-31 ~~~

DOWNLOAD:

Get Count of Files in Folder [Example].kmmacros (15 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


Example Output

In this case, no folder was selected in Finder, so the Window Target Folder was used.

image

image

ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Get a Count of ONLY Files in a Folder

How To Use

  1. Optionally, select a Folder in the Finder before you trigger this macro.
    • If a Folder is NOT selected, then the Target Folder of the Finder window is used.
  2. Trigger this macro.
    • It will then Prompt you to confirm/change the Folder
      (you can easily remove this Action if desired)
    • You can also choose to "Choose From List".
  3. Results are displayed (for information purposes).

NOTICE: This macro/script is just an Example

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • 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.

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. ??
      .
  1. Assign a Trigger to this maro..
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    *

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:

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user

ACTION COLOR CODES

  • To facilitate the reading, customizing, and maintenance of this macro,
    key Actions are colored as follows:
  • GREEN -- Key Comments designed to highlight main sections of macro
  • MAGENTA -- Actions designed to be customized by user
  • YELLOW -- Primary Actions (usually the main purpose of the macro)
  • ORANGE -- Actions that permanently destroy Variables or Clipboards,
    OR IF/THEN and PAUSE Actions

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge 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.

image

1 Like