ok so the same thing happens to me, which is good becasue at least it's a consistent issue. I guess relinking just doesn't produce an undo state (which is usuallysomething i'm looking for becasue most undo states just end up complicating things IMO.
But i did come up with a solution, though whether it's clever or even feasible is up to you... Basically what i did was save the original linked file object as a variable. then, relink the image, then pop up a dialog asking if you want to revert the change. As this is written, you'll have to make the decision to revert at runtime (like. after the script finishes, you can't go back and revert it. it's possible to save the file path to a local text file that could be read by some subsequent "revert" script.. But if you have multiple images, it might get a little confusing about which ones needs to be reverted and which ones don't).
**Edited to remove some arguments to the test function that weren't supposed to be there.
#target Illustrator
function test()
{
var doc = app.activeDocument;
var link = doc.placedItems[0];
var originalFile = link.file;
var newFile = File("path/to/new/file.ext");
link.relink(newFile);//this assumes that newFile does in fact exist
app.redraw(); //redraw the screen so that you can see the change before the dialog pops up
var w = new Window("dialog");
var msg = w.add("statictext",undefined,"Revert?");
var btnGroup = w.add("group");
var yes = btnGroup.add("button",undefined,"Yes");
var no = btnGroup.add("button",undefined,"No");
yes.onClick = function()
{
//revert the linked file
link.relink(originalFile);
w.close();
}
no.onClick = function()
{
//don't revert. just close the dialog and move on.
w.close();
}
w.show();
}
test();