/*Wrapping Applescript to embed it into an ImageJ macro. ------------------------------------------------------- 1. copy an AppleScript to the clipboard* 2. run macro "Wrap AppleScript" 3. now the clipboard contains macro "MyScript" (see below) that can be pasted and executed. *typically, the script is recorded and debugged in Apple's Script Editor; for a simple test, copy these three demo lines to empty the trash: tell application "Finder" empty trash end tell Unwrapping an Applescript: -------------------------- If you have lost the original script, you can recover it by unwrapping "MyScript": replace the line result = exec("osascript", "-e", String.buffer); by the line String.copy(String.buffer); Now run the modified "MyScript" macro and paste the unwrapped script into the Script Editor. */ macro "Wrap AppleScript"{ cr = "\r"; ss =String.paste; while (endsWith(ss, cr)) ss = substring(ss, 0, lengthOf(ss)-1); head = 'macro "myScript"{' + cr + " cr = fromCharCode(13);"+cr; head = head +" String.resetBuffer;" +cr +" String.append('"; fragment = "\' +cr); "+ cr + " String.append(\'"; aa = replace(ss, cr, fragment); tail = '\'); '+ cr + ' result = exec("osascript", "-e", String.buffer);' + cr + '}' + cr; String.copy(head + aa + tail); } //wrapped form of the "empty Trash" example: macro "myScript"{ cr = fromCharCode(13); String.resetBuffer; String.append('tell application "Finder"' +cr); String.append(' empty trash' +cr); String.append('end tell'); result = exec("osascript", "-e", String.buffer); }