You can make a layer that can be add textFrames to cut values. If you make a layer named "scriptWork", You can access like below app.activeDocument.layers.getByName("scriptWork"); therefor previouse code rewrite like below. var tx = app.activeDocument.layers.getByName("scriptWork").textFrames.add(); //tx as textFrame object If you select some object, replace "sel.selected = false;" to app.executeMenuCommand("deselectall"); Please note that I do not have test environment now and codes not tested. However, these may work.
... View more