You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用DXL脚本将剪贴板内容添加至已有Object Text开头?

Fix: Prepend Clipboard Content to Object Text via DXL

Let's get your script working properly! The main issue with your current code is relying on pasteToEditbox, which requires the object's text field to be actively open in the GUI—something scripts can't reliably trigger. Instead, we can directly read the clipboard content using DXL's built-in clipboard() function, then prepend it to the existing Object Text without needing any manual GUI interaction.

Corrected Script

// Get selected objects (your existing function, kept intact)
Skip fGetSelectedObjects(Module in_mod) {
    Skip skpObjects = create()
    if (null in_mod) return(skpObjects)
    Object oCurr = current, o
    for o in entire (in_mod) do {
        if (isSelected(o) or o == oCurr) put(skpObjects, o, o)
    }
    return(skpObjects)
}

// Main execution
Skip skpObjects = fGetSelectedObjects(current Module)
if (null skpObjects) {
    print "No objects selected or module is null\n"
    delete(skpObjects)
    exit
}

// Get clipboard content directly (no GUI activation needed!)
string clipboardContent = clipboard()
if (clipboardContent == "") {
    print "Clipboard is empty\n"
    delete(skpObjects)
    exit
}

Object o
for o in skpObjects do {
    // Get existing Object Text (handles rich text)
    RichText existingRT = o."Object text"
    string existingText = richTextString(existingRT)
    
    // Combine clipboard content + existing text (add space as per your example)
    string combinedText = clipboardContent " " existingText
    
    // Convert back to rich text and apply your indentation formatting
    RichText newRT = richText(combinedText)
    newRT = applyTextFormattingToParagraph(newRT, false, 360, 0)
    
    // Update the object's text
    o."Object text" = newRT
}

// Cleanup
delete(skpObjects)
print "Successfully prepended clipboard content to selected objects!\n"

Key Fixes & Explanations

  • Direct Clipboard Access: Used clipboard() to read the clipboard text directly, eliminating the need to activate the Object Text edit box. This is far more reliable for script automation.
  • Rich Text Handling: Properly converted between RichText and plain string to ensure formatting is preserved while modifying the content.
  • Error Checking: Added checks for empty clipboard and null selection to make the script more robust.
  • Indentation Preservation: Kept your existing applyTextFormattingToParagraph logic to maintain the 360-point indentation.

Example Result

If your existing Object Text is Already existing text in this object and clipboard content is My Clipboard text, the script will update the text to:

My Clipboard text Already existing text in this object

内容的提问来源于stack exchange,提问作者vivek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:31:24