Action

Send multiple Trello cards

Posted by enivrezvous, Last update 5 months ago

This script in Drafts streamlines the process of simultaneously creating multiple Trello cards with names and descriptions.

Each line in your Drafts note represents a Trello card and follows the format ‘Name | Description’ (where ‘Name’ is the card title and ‘Description’ is optional additional information, using the delimiter “|”. The script automatically extracts these elements and sends them to Trello, creating cards with the specified details.

To use this script, new users will need to update the ‘shortlink’ in the URL to match the link to their own Trello board. Simply replace ‘SHORTLINK’ with your Trello board’s shortlink.

To find your Trello board’s shortlink, follow these steps:

  1. Open Trello: Log in to your Trello account and open the board for which you want to find the shortlink.

  2. Open the Board Menu: In the upper right-hand corner of the board, you’ll find the “Show Menu” button (it looks like a three-dot icon). Click on it to open the board menu.

  3. Find More Options: In the board menu, scroll down to find the “More” section.

  4. Copy Shortlink: In the “More” section, you’ll see the “Copy Board Link” option. Click on it to copy the shortlink to your clipboard.

Now, you can use this shortlink in your Drafts script by replacing ‘SHORTLINK’ with the shortlink you copied. This will ensure that the script creates cards in the correct Trello board.

Keep in mind that the Trello shortlink is unique to each board, so you’ll need to perform these steps for each board you want to use with your Drafts script.

Steps

  • script (iOS only)

    // Split draft into lines
    const lines = draft.content.split("\n");
    
    // Base URL for Trello x-callback-url
    const baseURL = "trello://x-callback-url/createCard?shortlink=SHORTLINK&name=[[name]]&description=[[description]]";
    
    // Loop over lines and send each to Trello
    for (var line of lines) {
        if (line.length === 0) {
            continue; // Skip empty lines
        }
    
        // Split the line into name and description using "|" as a delimiter
        var parts = line.split("|");
        var name = parts[0].trim();
        var description = parts[1] ? parts[1].trim() : '';
    
        // Create and configure callback URL object
        var callbackURL = CallbackURL.create();
        var encodedName = encodeURIComponent(name);
        var encodedDescription = encodeURIComponent(description);
        callbackURL.baseURL = baseURL
            .replace("[[name]]", encodedName)
            .replace("[[description]]", encodedDescription);
    
        // Open and wait for result
        var success = callbackURL.open();
    
        if (!success) {
            if (callbackURL.status === "cancel") {
                context.cancel();
                break;
            } else {
                console.log("Failed to send line to Trello: " + name);
                context.fail();
                break;
            }
        }
    }
  • prompt (macOS only)

    promptKey
    prompt
    promptTitle
    Prompt
    promptMessage
    This action is available only on iOS, due to differences between the iOS and Mac version of Fantastical.
    promptButtons
    OK
    includeTextField
    false
    textFieldDefault
    includeCancelButton
    false

Options

  • After Success Trash
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.