function placeSnipInline( mySnipFile, text ) {One odd thing here might leap out at you. Why did I not take advantage of the returned object from the place() call to get a reference to the placed object rather than rely on myDoc.pageItems[0] in the store call? The reason is that I have just this morning discovered that if you place a snippet that consists of just a text frame, what's returned by place() is the story, not the text frame.
var myDoc = app.documents.add(false);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
myDoc.pages[0].place(mySnipFile);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
myLib = app.libraries.add(File("~/Desktop/templib.indl"));
myLib.store(myDoc.pageItems[0]);
myDoc.close(SaveOptions.no);
myLib.assets[0].placeAsset(text);
myLib.close();
File("~/Desktop/templib.indl").remove();
}
//DESCRIPTION: Place Snippet Inline/Anchored
if (app.documents.length > 0 &&
app.selection.length > 0 &&
app.selection[0].hasOwnProperty("baseline")) {
placeSnippet(app.selection[0]);
} else {
alert("There must be a text selection to run this script");
}
function placeSnippet(sel) {
if (File.fs == "Windows") {
var Filter = "Snippet files: *.inds";
} else {
var xmlFilter = function(file) {
while(file.alias){
file = file.resolve();
if (file == null) return false;
}
if (file instanceof Folder) return true;
return (file.name.slice(file.name.lastIndexOf(".")).toLowerCase() == ".inds");
}
var Filter = xmlFilter
}
var myFile = File.openDialog("Choose a snippet file", Filter);
if (myFile == null) { return }
placeSnipInline(myFile, app.selection[0]);
}