Skip to content

Instantly share code, notes, and snippets.

@kingtosh
Forked from UskeS/replaceLastObject.jsx
Created March 1, 2026 10:22
Show Gist options
  • Select an option

  • Save kingtosh/d3304ed73d07174d6806d76cd6dd55b3 to your computer and use it in GitHub Desktop.

Select an option

Save kingtosh/d3304ed73d07174d6806d76cd6dd55b3 to your computer and use it in GitHub Desktop.

Revisions

  1. @UskeS UskeS revised this gist Apr 16, 2019. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions replaceLastObject.jsx
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,14 @@ var newSelection = [];

    app.doScript(main, ScriptLanguage.JAVASCRIPT, null, UndoModes.ENTIRE_SCRIPT);
    function main(){
    var tempRuler = doc.viewPreferences.rulerOrigin;
    doc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
    for (var i=sel.length-2; i>=0; i--) {
    var n = tgt.duplicate([sel[i].visibleBounds[1], sel[i].visibleBounds[0]]);
    sel[i].remove();
    newSelection.push(n);
    }
    doc.viewPreferences.rulerOrigin = tempRuler;
    doc.selection = newSelection;
    };
    alert("終了しました");
    alert("終了しました");
    };
  2. @UskeS UskeS created this gist Apr 16, 2019.
    15 changes: 15 additions & 0 deletions replaceLastObject.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    var doc = app.activeDocument;
    var sel = doc.selection;
    var tgt = sel[sel.length-1];
    var newSelection = [];

    app.doScript(main, ScriptLanguage.JAVASCRIPT, null, UndoModes.ENTIRE_SCRIPT);
    function main(){
    for (var i=sel.length-2; i>=0; i--) {
    var n = tgt.duplicate([sel[i].visibleBounds[1], sel[i].visibleBounds[0]]);
    sel[i].remove();
    newSelection.push(n);
    }
    doc.selection = newSelection;
    };
    alert("終了しました");