Action

Send to OmniFocus

Posted by J-Astro, Last update 2 months ago

This action generates a concise task title by summarizing the content of the current draft and automatically sends it to OmniFocus. It uses GPT to analyze the content and return a clear, actionable task title. The original content is included as a note in OmniFocus for reference. Ideal for quickly converting detailed text into task titles for task management.

Steps

  • script

    // Function to generate task title based on the full content of the draft
    function generateTaskTitle() {
        // Initialize variables for the full content of the draft and cursor position
        const content = draft.content;
        const [st, len] = editor.getSelectedRange(); // Get the current cursor position
    
        // Hardcode the detailed prompt for OmniFocus task title generation, including examples
        const chatPrompt = `
    	
    	Given the following content:
    
        ${content}
    
        Your task is to carefully review the content in the message body and create a concise, relevant, and descriptive task title that accurately represents the main focus or action required based on the content.
    
        Requirements:
    
        - The task title should be clear and concise, typically 3-10 words.
        - It should accurately reflect the main topic or action described in the content.
        - Use action verbs when appropriate.
        - Avoid unnecessary words or articles (e.g., 'the', 'a', 'an') unless they are crucial for clarity.
    
        Desired output format: A single line containing the task title, without any additional formatting or punctuation.
    
        <example>
    
        Input: 
    
        The quarterly financial report needs to be prepared and submitted to the board of directors by the end of next week. This report should include an overview of our revenue, expenses, and profit margins for the past three months, as well as projections for the upcoming quarter.
    
        Output: Prepare Quarterly Financial Report for Board
    
        </example>
    
        Please review the content provided and create a suitable task title:
        `;
    
        // Send the prompt to ChatGPT
        let ai = new OpenAI();
        let taskTitle = ai.quickChatResponse(chatPrompt);
    
        // Check for valid reply
        if (!taskTitle || taskTitle.length == 0) {
            context.fail("No task title generated from GPT.");
            return;
        }
    
        // Prepare the new text with the result and original prompt
        const newText = taskTitle + '\n\n---\n# Original Prompt\n\n' + content;
    
        // Move the cursor to the original starting position and insert the new text
        editor.setSelectedRange(st, 0);
        editor.setSelectedText(newText);
    
        // Move the cursor to the end of the newly inserted text
        editor.setSelectedRange(st + newText.length, 0);
    
        // Display success message
        app.displaySuccessMessage("Task title generated and text updated.");
    }
    
    // Execute the function
    generateTaskTitle();
  • callbackUrl

    template
    omnifocus://x-callback-url/add?name=[[title]]¬e=[[body]]
    waitForResponse
    false
    encodeTags
    true

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.