Assistance Needed with CSV Data Import to Populate Prompt with List

Subject: Prompt With List Limited to 20 Items? Assistance Needed with CSV Data Import

Hello Keyboard Maestro Community,

I’m working on a macro that reads data from a CSV file and uses the “Prompt With List” action to display a list of authors for selection. However, I’ve encountered an issue where only the first 20 entries from the CSV file are displayed in the prompt, even though the CSV file contains more than 20 entries.

Here’s what I’m trying to achieve:

Read a CSV file (authors.csv) containing author information.

Generate a list of authors, where each list item includes display information and all author data, separated by unique delimiters.

Use “Prompt With List” to allow the user to select an author from the generated list.

Parse the selected entry to extract individual author data fields for use in automating data entry tasks.

The Issue:

• When the CSV file has more than 20 entries, only the first 20 entries appear in the “Prompt With List” dialog.

• If I insert a new entry into the CSV file at a position between rows 1-20, the new entry shows up, but the entry that moves to position 21 is no longer displayed.

• Executing the shell script directly in the macro or using debugging actions confirms that only 20 lines are being processed and output.

What I’ve Tried:

  1. Original Shell Script:
#!/bin/bash

csvFilePath="/path/to/authors.csv"

# Check if the file exists
if [ ! -f "$csvFilePath" ]; then
  >&2 echo "CSV file not found at path: $csvFilePath"
  exit 1
fi

# Read the CSV file and skip the header
tail -n +2 "$csvFilePath" | while IFS=, read -r AuthorID FirstName MiddleInitial LastName Email Credentials; do
    # Construct display name
    if [ -n "$MiddleInitial" ]; then
        DisplayName="$FirstName $MiddleInitial. $LastName [$AuthorID]"
    else
        DisplayName="$FirstName $LastName [$AuthorID]"
    fi

    # Create a line with display name and all data, separated by a unique delimiter
    echo "$DisplayName|||$AuthorID|$FirstName|$MiddleInitial|$LastName|$Email|$Credentials"
done
  1. Modified Shell Script (Avoiding Piping):
#!/bin/bash

csvFilePath="/path/to/authors.csv"

# Check if the file exists
if [ ! -f "$csvFilePath" ]; then
  >&2 echo "CSV file not found at path: $csvFilePath"
  exit 1
fi

# Read the CSV file, skip the header, and process each line
{
  # Read and discard the header line
  IFS= read -r header

  # Process each line
  while IFS=, read -r AuthorID FirstName MiddleInitial LastName Email Credentials; do
      # Construct display name
      if [ -n "$MiddleInitial" ]; then
          DisplayName="$FirstName $MiddleInitial. $LastName [$AuthorID]"
      else
          DisplayName="$FirstName $LastName [$AuthorID]"
      fi

      # Create a line with display name and all data, separated by a unique delimiter
      echo "$DisplayName|||$AuthorID|$FirstName|$MiddleInitial|$LastName|$Email|$Credentials"
  done
} < "$csvFilePath"
  1. Debugging Attempts:

• Added “Display Text” actions to show the contents of the AuthorList variable.

• Confirmed that only 20 lines are output, matching the behavior of the “Prompt With List” action.

• Verified that edits to entries within the first 20 lines are reflected, but any entries beyond line 20 are not processed or displayed.

Observations:

• It seems like there might be a limit of 20 items for the “Prompt With List” action or perhaps within the shell script processing in Keyboard Maestro.

• The CSV file is properly formatted, and the file path is correct.

• When running the shell script independently in Terminal, all entries are processed and displayed correctly.

CSV File Example (Simplified):

AuthorID,FirstName,MiddleInitial,LastName,Email,Credentials
Author1,First1,,Last1,email1@example.com,Credentials1
Author2,First2,,Last2,email2@example.com,Credentials2
...
Author21,First21,,Last21,email21@example.com,Credentials21

Questions:

  1. The limit to the number of items that can be processed or displayed in the “Prompt With List” action is 99, correct?

  2. Is there a limitation within Keyboard Maestro’s shell script processing that could be causing only the first 20 lines to be read?

  3. Are there alternative approaches to process and display more than 20 items from a CSV file within Keyboard Maestro?

Additional Details:

• I’m using Keyboard Maestro version Version 11.0.3 on macOS Seqoia 15.0.

• The macro works perfectly with 20 or fewer entries.

• The issue persists even after restarting Keyboard Maestro and the macOS system.

Any assistance or suggestions would be greatly appreciated!

Thank you in advance for your help.

Can you show your Prompt With List action? And can you provide a sample of the CSV data with more than 20 rows?

There's certainly no inherent limit on Prompt With List:

But without seeing your data or how you're trying to use it in the Prompt With List, it's hard to say for certain what the problem might be.

-rob.

CSV data replaced with aliases, formatting unchanged

AuthorID,FirstName,MiddleInitial,LastName,Email,Credentials
Author_001,AuthorA,,AliasA,author001@example.com,MD
Author_002,AuthorB,,AliasB,author002@example.com,MD PhD
Author_003,AuthorC,,AliasC,author003@example.com,MD
Author_004,AuthorD,,AliasD,author004@example.com,MD
Author_005,AuthorE,P,AliasE,author005@example.com,MD MBA
Author_006,AuthorF,D,AliasF,author006@example.com,MD
Author_007,AuthorG,,AliasG,author007@example.com,MD
Author_008,AuthorH,,AliasH,author008@example.com,MD
Author_009,AuthorI,,AliasI,author009@example.com,MPH
Author_010,AuthorJ,,AliasJ,author010@example.com,BS
Author_011,AuthorK,,AliasK,author011@example.com,BS
Author_012,AuthorL,H,AliasL,author012@example.com,BS
Author_013,AuthorM,,AliasM,author013@example.com,BS
Author_014,AuthorN,,AliasN,author014@example.com,BS
Author_015,AuthorO,,AliasO,author015@example.com,BS
Author_016,AuthorP,,AliasP,author016@example.com,Undergrad
Author_017,AuthorQ,,AliasQ,author017@example.com,BS
Author_018,AuthorR,,AliasR,author018@example.com,BS
Author_019,AuthorS,,AliasS,author019@example.com,BS
Author_020,AuthorT,,AliasT,author020@example.com,BS

CleanShot 08-10-2024 at 19.17.36

My advice might be wrong, but did you try setting the flag "Always show all entires" in the cogwheel of the Prompt with List action?

1 Like

Do it in KM rather than shelling out:

Authors to Prompt.kmmacros (7.6 KB)

Image

Note that I've used the "friendly list" format, so only your DisplayName above shows in the prompt, but all data for the choice goes into the Local_chosenAuthor variable.

I realise that doesn't answer your original question -- but your shell script works fine in a simple test. This behaves as expected for a list of 300 authors, displaying with zero items ("Show all entries" turned off) or all 300 ("Show all entries" turned on).

Authors to Prompt (shell).kmmacros (4.8 KB)

Image

Unless you can post a cut-down version of your macro that demonstrates the problem it'll be difficult to replicate, then troubleshoot, your issue.