如何使用Google Apps Script调整Google Slides中的形状Adjustments参数
Great question—this is definitely one of those features that’s intuitive in the UI but not super obvious in the Apps Script docs at first glance. Let’s break this down clearly:
The Short Answer
Google Apps Script does have an equivalent to VBA's Adjustments property for shapes in Slides. You’ll use the Shape.getAdjustments() method, which returns an AdjustmentCollection object. Each item in this collection maps directly to one of those yellow control handles you see in the Slides UI.
Example Code Walkthrough
Let’s use common use cases like adjusting a pie chart slice offset or an arrow’s head width to show how this works:
First, access your target shape and its adjustment handles
function tweakShapeControls() { const presentation = SlidesApp.getActivePresentation(); const targetSlide = presentation.getSlides()[0]; // Grab the first slide (adjust as needed) const targetShape = targetSlide.getShapes()[0]; // Grab the first shape on the slide const adjustments = targetShape.getAdjustments(); Logger.log(`This shape has ${adjustments.length} control handles`); }Modify a specific adjustment handle
Each adjustment uses a zero-based index. The index corresponding to each yellow handle varies by shape type—you’ll need to test with your specific shape to find the right one. For example:// Adjust the first control handle (index 0) to 20% of its maximum range adjustments.get(0).setValue(0.2);- For pie charts, index 0 typically controls the slice pull-out offset.
- For arrows, index 0 might control head width, while index 1 controls tail width.
Important Details to Keep in Mind
- Value ranges depend on the shape: Most adjustments use a 0–1 scale (0 being the minimum, 1 the maximum), but some shapes (like pie charts) allow values beyond 1 for more extreme adjustments.
- Not all shapes have adjustments: Basic shapes like rectangles or circles won’t have any adjustment handles—only dynamic shapes (arrows, callouts, chart slices) do.
- Test to find the right index: Use
Logger.logto check how many adjustments your shape has, then tweak values one by one to map each index to its corresponding yellow handle.
Why This Was Tricky to Find
The AdjustmentCollection documentation is tucked under the Shape class in Apps Script, so it’s easy to miss if you’re searching for terms like "yellow handles" or "shape controls" instead of "adjustments".
内容的提问来源于stack exchange,提问作者RSM_Tools

