This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy-name-to-clipboard.jsx
86 lines (74 loc) · 2.04 KB
/
copy-name-to-clipboard.jsx
1
(function (thisObj) { main(); function main() { var doc = app.activeDocument; if (doc === null) { alert("No document"); return; } if (doc.selection.length === 0) { alert("No selction"); return; } var sel = app.selection[0]; var link = null; if (sel.hasOwnProperty('images')) { if (sel.images.length === 0) return; link = sel.images[0].itemLink; } else if (sel instanceof Image) { link = sel.itemLink; } if (link === null) { alert("This is not an image frame nor an image."); return; } run_shell_cmd(link.name); // if(link.needed === false){ // alert("embedded"); // return; // } // var path = ""; // if(link.status == LinkStatus.LINK_MISSING){ // alert("image is missing"); // return; // } // var img = File(path); // alert(img.path); } function run_shell_cmd(n) { if (n === null) return; myScript = 'do shell script "echo \'' + n + '\' | pbcopy"'; app.doScript(myScript, ScriptLanguage.applescriptLanguage); message("--- copied " + n + " to clipboard ---", 2000); } /** * Taken from ScriptUI by Peter Kahrel * @usage * var progress_win = new Window ("palette"); * * var progress = progress_bar(progress_win, 100, 'my Progress'); * * progress.value = i++; * progress.parent.close();// important close it!! * * @param {Palette} w the palette the progress is shown on * @param {Number} stop [description] * @return {Progressbar} [description] */ function message(labeltext, millisec) { var w = new Window("palette"); var txt = w.add('statictext', undefined, labeltext); // var pbar = w.add ("progressbar", undefined, 1, stop); pbar.preferredSize = [300,20]; w.show(); sleep(millisec); w.close(); } function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++) { if ((new Date().getTime() - start) > milliseconds) { break; } } }})(this);