Skip to content

Instantly share code, notes, and snippets.

@moluapple
Created November 29, 2011 10:04
Show Gist options
  • Save moluapple/1404260 to your computer and use it in GitHub Desktop.
Save moluapple/1404260 to your computer and use it in GitHub Desktop.
Indesin_Search&Link Embed Image by Filename
(function (){
app.findGrepPreferences.findWhat = '~a\r.+';
var d = app.activeDocument,
f = Folder.selectDialog ('选中图像根目录文件夹'),
R = d.findGrep(),
RL = R.length, i = 0;
for (; i < RL; i++){
var images = getFileFromFolder(f, R[i].contents.match(/\S{2,}/)[0]),
real;
if (images){
real = images.length == 1 ? images[0] : (function (){
var j = 0, embedSize = R[i].characters[0].allGraphics[0].itemLink.size;
for (; j < len; j++){
if (images[j].length == embedSize) return images[j];
}
return images[0];
})();
try {R[i].characters[0].rectangles[0].place(real)} catch (e) {}
}
}
app.findGrepPreferences = NothingEnum.nothing
function getFileFromFolder (f, str) {
var regex = RegExp(str),
a = f.getFiles(function (F){return regex.test(F.fsName)}),
sub = f.getFiles(function (F) {return F instanceof Folder}),
l = sub.length, i = 0, G;
if (a.length > 0) {
return a;
} else {
for (; i < l; i++){
G = getFileFromFolder (sub[i], str);
if (G) return G;
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment