Explorer, right click a single file, properties...
Shows File Properties Dialog.
I am hoping there is a direct way to do this from the command line, which explains my complete lack of research on how to do it with the win api :)
Answering my own question. I put together this script from the links provided. There is probably a more direct way -- this has a Frankenstein-like aura to it, but it works. The drawback is that there is a hack to keep the dialog open (sleep the script) that can be changed to two different methods. This script will exec any verb, as well as list the verbs.
Usage: save script as shareGUI.js, call with cscript shareGUI.js <args>
Examples:
cscript shareGUI.js C:\path\to\file.txt will list verbs
cscript shareGUI.js <verb> C:\path\to\file.txt will execute given verb
cscript shareGUI.js "Properties" C:\path\to\file.txt will show properties dialog
Include usual disclaimers in bold type.
var args = WScript.Arguments;
var usage="Usage: cscript shareGUI.js [verb] <fullpath>";
useage+="\n Function: Executes given verb on given file";
useage+="\n or lists available verbs";
useage+="\n Notes: Ampersands in property names are remove in listing";
useage+="\n Ampersands are not required when specifying verb";
useage+="\n Arguments: ";
useage+="\n verb (optional): Name of verb to be executed, case sensative";
useage+="\n if not provided, verbs are listed";
useage+="\n fullpath: FULLPATH Name of file or directory";
//
if ((args.Unnamed.length == 0) || (args.Named.Exists("?"))) {
QuitMsg(usage,0);
}
if (args.Unnamed.length > 2) {
QuitMsg(usage,0);
}
//
var tgt_;
var verb_;
if (args.Unnamed.length == 1) {
tgt_=args.Unnamed.Item(0);
verb_ = "";
}else if (args.Unnamed.length == 2) {
verb_ = args.Unnamed.Item(0);
tgt_=args.Unnamed.Item(1);
}
//
var shellApp = new ActiveXObject("Shell.Application");
QuitIfNull(shellApp,"System Error:Could not get Shell.Application ActiveXObject",2);
//
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
QuitIfNull(objFSO,"System Error:Could not get Scripting.FileSystemObject ActiveXObject",2);
//
var WSHshell = new ActiveXObject("Wscript.Shell");
QuitIfNull(WSHshell,"System Error:Could not get Wscript.Shell ActiveXObject",2);
//
var doList=verb_=="";
//
var isDir=objFSO.FolderExists(tgt_);
if (isDir) {
DoForFolder();
}else{
DoForFile();
}
WScript.Quit(0);// EXIT OK
// functions...
// redundant code prequel
function DoForFile(){
var objFile = objFSO.GetFile(tgt_);
QuitIfNull(objFile,"Error:Path \""+tgt_+"\" Not Found",3);
//
var folder = shellApp.NameSpace(objFSO.GetParentFolderName(objFile));
QuitIfNull(folder,"System Error:Could not get parent folder name of \""+tgt_+"\"",3);
//
var folderItem=folderItemFromFolder(tgt_,folder);
QuitIfNull(folderItem,"System Error:Could not folder item from parent folder of \""+tgt_+"\"",3);
//
if (doList) {
listItemVerbs(folderItem);
return;
}
var folderItemVerb=folderItemVerbFromFileItem(verb_,folderItem);
QuitIfNull(folderItemVerb,"System Error:Could not folder item verb from folder item \""+tgt_+"\"",3);
//
runTheVerb(folderItemVerb);
}
// redundant code redux
function DoForFolder(){
var folder = shellApp.NameSpace(tgt_);
QuitIfNull(folder,"System Error:Could not folder of \""+tgt_+"\"",2);
//
var folderItem=folder.Self;
QuitIfNull(folderItem,"System Error:Could not folder item of \""+tgt_+"\"",2);
//
if (doList) {
listItemVerbs(folderItem);
return;
}
var folderItemVerb=folderItemVerbFromFileItem(verb_,folderItem);
QuitIfNull(folderItemVerb,"System Error:Could not folder item verb from folder item \""+tgt_+"\"",3);
//
runTheVerb(folderItemVerb);
}
// HACK!! this part sucks, have to remain open else dialog dies
function runTheVerb(verb){
verb.DoIt();
WSH.Sleep(5000);
var focus_way=false;
if (focus_way) {
while (WSHshell.AppActivate("Properties")) {WSH.Sleep(2000)};
}else{ // forever way
WSH.Sleep(60*60*1000);// sleep for 60 minutes !
}
}
// match path and return folder item
function folderItemFromFolder(path,folder){
var folderItems = new Enumerator(folder.Items());
for (; ! folderItems.atEnd(); folderItems.moveNext()) {
var folderItem = folderItems.item();
if (folderItem.Path==tgt_) {
//WScript.Echo("tgt_:"+folderItem.Path);
//WScript.Quit(0);
return folderItem
}
}
return null;
}
// match verb name
function folderItemVerbFromFileItem(verb,folderItem){
verb=verb.replace('&','');
var folderItemVerbs = new Enumerator(folderItem.Verbs());
for (; ! folderItemVerbs.atEnd(); folderItemVerbs.moveNext()) {
var folderItemVerb = folderItemVerbs.item();
//WScript.echo("Verb:"+folderItemVerb );
var fix_n=folderItemVerb.Name.replace('&','');
if (fix_n == verb) {
return folderItemVerb;
}
}
return null;
}
// echo the verbs, ignore blanks, remove ampersands
function listItemVerbs(folderItem){
var folderItemVerbs = new Enumerator(folderItem.Verbs());
for (; ! folderItemVerbs.atEnd(); folderItemVerbs.moveNext()) {
var folderItemVerb = folderItemVerbs.item();
var fix_n=folderItemVerb.Name.replace('&','');
if (fix_n!="") {
WScript.echo(""+fix_n );
}
}
}
function QuitIfNull(who,why,how){
if (who==null) {
QuitMsg(why,how);
}
}
function QuitMsg(why,how){
WScript.Echo(why);
WScript.Quit(how);
}
Related
Been struggling to get this script to work. It's meant to batch export notes out of Apple Notes. Script is below.
// set things up
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var notesApp = Application('Notes');
notesApp.includeStandardAdditions = true;
// choose which notes
var notes = notesApp.notes;
var whichNotes = app.chooseFromList(notes.name(), { withPrompt: "Which Notes?", multipleSelectionsAllowed: true });
if (whichNotes) {
// choose save location
var saveWhere = app.chooseFolder().toString();
if (saveWhere) {
// loop through all notes
for(var i=0; i<notes.length; i++) {
// is this note one to be exported?
if (whichNotes.indexOf(notes[i].name()) > -1) {
// save file as html
var filename = saveWhere+"/"+notes[i].name()+".html";
var file = app.openForAccess(Path(filename), { writePermission: true });
app.setEof(file, { to: 0 });
app.write(notes[i].body(), {to: file});
app.closeAccess(file);
}
}
}
}
A bunch of other people have used it with no problems.
I have the same problem with the same script on 10.15.7. The issue is raised on notes.name().
I assume this is related to either too many notes (it used to work, but I created a lot of notes since), or some special char in the note title. But I did not managed to fix it with my notes.
I copied my version below.
(notice the replace to build a valid file name if your note title contain "/".)
// set things up
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var notesApp = Application('Notes');
notesApp.includeStandardAdditions = true;
// choose which notes
var notes = notesApp.notes;
this.console.log("before notes.name()")
var whichNotes = app.chooseFromList(notes.name(), { withPrompt: "Which Notes?", multipleSelectionsAllowed: true });
this.console.log("After notes.name()")
this.console.log("Let's do it") // view / show log / message tab
if (whichNotes) {
// choose save location
var saveWhere = app.chooseFolder().toString();
if (saveWhere) {
this.console.log("note count:"+notes.length)
// loop through all notes
for(var i=0; i<notes.length; i++) {
// is this note one to be exported?
if (whichNotes.indexOf(notes[i].name()) > -1) {
// save file as html
var notename = notes[i].name().replace(/\//gi,'-')
this.console.log("next:"+notename) // view / show log / message tab
var filename = saveWhere+"/"+ notename +".html";
var file = app.openForAccess(Path(filename), { writePermission: true });
app.setEof(file, { to: 0 });
app.write(notes[i].body(), {to: file});
app.closeAccess(file);
}
}
}
}
I'm using dropzone.js to be able to easily upload files and folders. I do not get an notification for empty folders, is there any way to have an event fired for empty folders?
Thank you.
So this is what I came up with, not the most elegant solution, but does what I need to be able to handle emptyfolders. Would be great if dropzone.js had an option for enabling emptyfolders to be returned.
I made the following changes to the dropzone.js
At the very top I added
var passedFolders = [];
// used to store the names of fodlers that were passed, with either files or without
// the key is the path name, the value is true if empty, false if it had contents
Then under the section
var readEntries = function readEntries() {
return dirReader.readEntries(function (entries) {
change it to
var readEntries = function readEntries() {
return dirReader.readEntries(function (entries) {
if (entries.length > 0) {
var _iterator7 = dropzone_createForOfIteratorHelper(entries, true),
_step7;
try {
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
var entry = _step7.value;
if (entry.isFile) {
//There is a a file in the folder, so we can set it's value to false
passedFolders[entry.fullPath.substring(0, entry.fullPath.lastIndexOf(entry.name)-1)] = false //-1 to remove the last slash
entry.file(function (file) {
if (_this5.options.ignoreHiddenFiles && file.name.substring(0, 1) === ".") {
return;
}
file.fullPath = "".concat(path, "/").concat(file.name);
return _this5.addFile(file);
});
} else if (entry.isDirectory) {
//This is just a folder, not a file. Store the folder path information set to true, it will remain true if the folder remains empty
passedFolders[entry.fullPath] = true;
_this5._addFilesFromDirectory(entry, "".concat(path, "/").concat(entry.name));
}
} // Recursively call readEntries() again, since browser only handle
// the first 100 entries.
// See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries
} catch (err) {
_iterator7.e(err);
} finally {
_iterator7.f();
}
readEntries();
}
return null;
}, errorHandler);
};
Now passedFolders will contain an associate array, where the key is the pathname and the value is true if it is empty, false if it contained files.
Then under the dropzone init, when the file uploads are complete you can choose what to do with empty folders
this.on('queuecomplete', function (file, json) {
alert("Uploads complete, now we can deal with the empty folders");
for (var key in passedFolders) {
if (passedFolders[key]) {
alert(key);
}
}
});
I have Photoshop CC2019 PSD document containing several smart objects that contains other smart objects that contains other smart objects. Some of these have linked layers. Normally, such images are not updated automatically (which is extremely annoying, Adobe!) but you have to manually update each of them once the linked image content has changed.
There is a .jsx script file named "Update All Modified Content.jsx" which auto-updates linked layers (PNG image in my case) but only if the smart object is in the top most document - that is no nested smart objects with linked layers are updated automatically.
My question is: does anyone know how to update the content of the above mentioned .jsx file so that it would auto-update all linked images across all the smart objects in PSD document including nested ones?
For those who care or would be willing to help updating the code here it is:
// Update all modified content
var idplacedLayerUpdateAllModified = stringIDToTypeID( "placedLayerUpdateAllModified" );
executeAction( idplacedLayerUpdateAllModified, undefined, DialogModes.NO );
So, after spending half a day with it I finally solved it myself. Here is the code:
#target photoshop
// SET INITIAL ACTIVE DOCUMENT
var mainDocument = app.activeDocument;
// SAVE THE DOCUMENT NAME FOR FUTURE USE
var mainDocName = mainDocument.name;
// RUN THE MAIN UPDATE FUNCTION
mainDocument.suspendHistory("processAllSmartObjects", "autoupdateAllSmartObjects(mainDocument, 0)");
// FINALLY SAVE THE MAIN DOCUMENT
mainDocument.save();
function autoupdateAllSmartObjects(theParent, prevVal) {
// FUNCTION TO TEST IF SMARTOBJECT IS LINKED
function isLinkedSO(obj) {
var localFilePath = "";
var ref = new ActionReference();
ref.putIdentifier(charIDToTypeID('Lyr '), obj.id);
var desc = executeActionGet(ref);
var smObj = desc.getObjectValue(stringIDToTypeID('smartObject'));
var isLinked = false;
// TEST IF IT HAS LINKED FILE
try {
var localFilePath = smObj.getPath(stringIDToTypeID('link'));
isLinked = true;
} catch(e) {
//
}
return isLinked;
}
// FUNCTION TO UPDATE LINKED SMART OBJECT
function doTheUpdate(LYR, stackNr) {
// SET ACTIVE LAYER TO ACTUALY ITERATED ONE
app.activeDocument.activeLayer = LYR;
// RUN IN "SILENT" MODE
app.displayDialogs = DialogModes.NO;
var layer = app.activeDocument.activeLayer;
// IF ACTIVE LAYER IS SMARTOBJECT
if (layer.kind == "LayerKind.SMARTOBJECT") {
//alert(layer);
// OPEN THE SMARTOBJECT
app.runMenuItem(stringIDToTypeID('placedLayerEditContents'));
// DO THE ACTUAL FILE UPDATE
var idplacedLayerUpdateAllModified = stringIDToTypeID( "placedLayerUpdateAllModified" );
executeAction( idplacedLayerUpdateAllModified, undefined, DialogModes.NO);
// IF IT IS NOT THE "CORE/MAIN" DOCUMENT
if(stackNr > 0) {
// SAVE CHANGES (UPDATE) AND CLOSE IT
app.activeDocument.close(SaveOptions.SAVECHANGES);
}
// CONTINUE INSIDE THIS ACTIVE SMARTOBJECT
autoupdateAllSmartObjects(app.activeDocument, stackNr);
}
return;
}
// FUNCTION TO PARSE GROUPS
function parseGroup(LYR) {
var groupLayers = LYR.layers;
// IF GROUP IS NOT EMPTY
if(groupLayers.length > 0) {
// PARSE ALL LAYERS IN THE GROUP
for (var i = groupLayers.length - 1; i >= 0; i--) {
var lyr = groupLayers[i];
// IF NOT LOCKED = NOT EDITABL:E
if(!lyr.allLocked) {
// YET ANOTHER GROUP?
if (lyr.typename == "LayerSet") {
// IF IT IS NOT EMPTY
if (lyr.layers.length > 0) {
// RE-RUN THE SCRIPT ANEW WITH THE SELECTED GROUP AS LAYERS SOURCE
autoupdateAllSmartObjects(lyr, 0);
}
// LAYERS
} else if (lyr.typename == "ArtLayer") {
// IF THE LAYER IS SMARTOBJECT
if (lyr.kind == LayerKind.SMARTOBJECT) {
// IF THE LAYER IS SET TO "visible" (THAT IS: NOT DISABLED)
if(lyr.visible){
// TEST IF THE SMARTOBJECT IS ACTUALLY LINKED
if(!isLinkedSO(lyr)) {
// RUN THE UPDATE SUB-FUNCTION
doTheUpdate(lyr, i);
}
}
}
}
}
}
}
}
// PARSE ALL THE LAYERS
for (var i = theParent.layers.length - 1 - prevVal; i >= 0; i--) {
var theLayer = theParent.layers[i];
// ONLY ArtLayers
if (theLayer.typename == "ArtLayer") {
// IF THE LAYER IS SMARTOBJECT
if (theLayer.kind == LayerKind.SMARTOBJECT) {
// IF THE LAYER IS SET TO "visible" (THAT IS: NOT DISABLED)
if(theLayer.visible){
// TEST IF THE SMARTOBJECT IS ACTUALLY LINKED
if(!isLinkedSO(theLayer)){
// RUN THE UPDATE SUB-FUNCTION
doTheUpdate(theLayer, i);
// IF WE ARE AT THE LAST LAYER IN THE STACK AND IT IS NOT OUR MAIN DOCUMENT
if(i == 0 && app.activeDocument.name !== mainDocName) {
// SAVE CHANGES (UPDATE) AND CLOSE IT
app.activeDocument.close(SaveOptions.SAVECHANGES);
}
}
}
}
// ONLY Groups
} else if (theLayer.typename == "LayerSet") {
// RUN SUB-FUNCTION FOR GROUP PARSING
parseGroup(theLayer);
// ANYTHING ELSE
} else {
autoupdateAllSmartObjects(theLayer, m);
}
}
return;
};
OP's script works!! It was going in loops for me too but after some trial and error, I realised that my smart objects (SO) that are linked across artboards ( - e.g. if you change one SO, it changes on various artboards) - were the issue. I hid all such SO and it works.
so basically, it only works for Smart Objects + copies made via 'New smart object via copy' NOT 'duplicate layer' / copypaste smart objects. If your work contains a 'duplicate layer' SO - it will break the script. You need to hide these objects ( or not work like that all together) before running the script
While it looks like you can change the order of a tab within a window by updating the tab .index property, it doesn't look like the tabs api directly supports the move of a tab to another window.
Am I missing something? Is there a viable workaround?
It is possible through the low level module window/utils. The example below duplicates the active tab across every open window
const { getMostRecentBrowserWindow, windows: getWindows } = require("sdk/window/utils");
const { ActionButton } = require("sdk/ui/button/action");
var button = ActionButton({
id: "duplicatetab-button",
label: "Duplicate tab",
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACUElEQVQ4jaWTTWtTURCGjzc33CCpbVKN4kexC9EUY1Hov+iqPyDrbgtuCrViKUERqsWVguBGQaW4UiKiaEVxoShFGgnuBMUqNW3zce49Z+ZxUWtwoRR8YXbzPswM7xj+JgVEiXGsYVknxgII4Ltt5p8AB8RArOAUVQfqQJNtAFA8QgvF6i9PR1Dt0KbVBTjncM4hIni/OZv3HsRB+wvefiP2LcQnJIkQe49FEJFNQLPZZHh4mEwmQyqVoqenh3K5TGvlK1dOlageH+HG4DFar1/S0A6Lr99xdN8QxWKRXC6HGR0dJZvNMjk5Sb1ep1gskk6nuTo/D+/ec7dvkBdhP9cKeX7UXxEZQ2/YRxRFLC8vY+bm5qhUKnjvsdYyPj5OFEWcnTnHujiS5TfcPDbAw50h9w7u5f7UadLZFLVaDRHBiGzuY61lbGyMXC5HoVBgrbGGWAW/TvvxHR7s7udFKs/1oyfZ+PSRTqeDqm7eoFqtEoYhmUyG2dlZVJU4iREfI/WP3Nt9iMUdu7jdf5Anly5i0oaVlRWazSZmYWGBIAiIoohyucz09DQTExPMnJli9dlT5vcM8Kh3gFsHDuNqb9mb7yXMRBhjWFpawpRKJVKpFMYYgiAgDEOCIOD81BkunBjh8pEhKqUhGkvP6bQ/U//wgUP5/YRhSDabxbTbbVQV5xyq2q0kgR8NdOM7JKuo/Y5qggqIdPvMlnkrQCKCquJFsOrxeHAJxA48eFU6Xv4EqOpv41YqnQirqliv4MEmQtN7RBSs7wL+/gvb038DfgJnyUabbHzUbQAAAABJRU5ErkJggg==",
onClick: function() {
var xulwindows = getWindows("navigator:browser");
var xulactivewindow = getMostRecentBrowserWindow();
var xulactivetab = xulactivewindow.gBrowser.selectedTab;
xulwindows.forEach(function(win){
if(win === xulactivewindow)
return;
var duplicatedtab = win.gBrowser.duplicateTab(xulactivetab);
win.gBrowser.moveTabTo(duplicatedtab, 0); // the second argument is the index
});
}
});
#paa's solution is nice but it doesn't move a tab. His is duplicating the tab. So flash movies will not retain their position etc. And its not a move its a duplicatio, like he explained.
I did a lot of research was real fun. The way they move tabs in Firefox is via docShell swapping. This will accomplish what you want. It's written for bootstrap though so needs touch up for addon sdk.
Pass second argument as string of tabbed or non-tabbed if you want to move it to a new window. Else pass second argument an existing window and it will be moved there. can copy paste and run this code from sratchpad.
this uses the gBrowser.swapBrowsersAndCloseOther function
function moveTabToWin(aTab, tDOMWin) {
//tDOMWin means target DOMWindow means the window you want the tab in
//if tDOMWin == 'tabbed' or == 'non-tabbed' it opens in a new window
//if aTopContWin is the last in its window, then its window is closed
if (tDOMWin == 'tabbed' || tDOMWin == 'non-tabbed') {
var sa = Cc["#mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
var wuri = Cc["#mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
wuri.data = 'about:blank';
sa.AppendElement(wuri);
let features = "chrome,dialog=no";
if (tDOMWin == 'tabbed') {
features += ',all';
}
var sDOMWin = aTab.ownerGlobal; //source DOMWindow
if (PrivateBrowsingUtils.permanentPrivateBrowsing || PrivateBrowsingUtils.isWindowPrivate(sDOMWin)) {
features += ",private";
} else {
features += ",non-private";
}
var XULWindow = Services.ww.openWindow(null, 'chrome://browser/content/browser.xul', null, features, sa);
XULWindow.addEventListener('load', function() {
var DOMWindow = XULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
DOMWindow.gBrowser.selectedTab.linkedBrowser.webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL);
DOMWindow.gBrowser.swapBrowsersAndCloseOther(DOMWindow.gBrowser.selectedTab, aTab);
//DOMWindow.gBrowser.selectedTab = newTab;
}, false);
} else if (tDOMWin) {
//existing dom window
var newTab = tDOMWin.gBrowser.addTab('about:blank');
newTab.linkedBrowser.webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL);
tDOMWin.gBrowser.swapBrowsersAndCloseOther(newTab, aTab);
tDOMWin.gBrowser.selectedTab = newTab;
}
}
moveTabToWin(gBrowser.selectedTab, 'tabbed');
I'v got inspired by #Noitidart's answer and came up with my solution.
I'm adding setWindow(window, index) method to Tab's prototype, so that any SDK tab can be moved to another window from anywhere in the addon with a simple call like this:
browserWindows[0].activeTab.setWindow(browserWindows.activeWindow, 0);
This will move active tab of window 0 to the beginning of active window.
And here is the method:
Update:
I've put together a module to do exactly this: jetpack-tab-setwindow
Old solution (breaks in FF43)
var Tab = require("sdk/tabs/tab").Tab;
Tab.prototype.setWindow = function (window, index) {
var tab = this;
var oldWindow = tab.window;
if ( oldWindow !== window ) {
// We have to use lower-level API here
var Ci = require('chrome').Ci;
var viewFor = require("sdk/view/core").viewFor;
var aTab = viewFor(tab);
var aWin = viewFor(window);
var gBrowser = aWin.gBrowser;
// Get tab properties
var isSelected = oldWindow.activeTab == tab;
var isPinned = aTab.pinned;
// Log for debugging:
var tabId = tab.id;
console.log('setWindow', {index, isSelected, isPinned, tab, tabId});
// Create a placeholder-tab on destination windows
var newTab = gBrowser.addTab('about:newtab');
newTab.linkedBrowser.webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL); // we don't need this tab anyways
// If index specified, move placeholder-tab to desired index
if ( index != undefined ) {
var length = gBrowser.tabContainer.childElementCount;
if ( index < 0 ) index = length - index;
if( 0 <= index && index < length ) {
gBrowser.moveTabTo(newTab, index);
}
}
// Copy tab properties to placeholder-tab
if ( isPinned ) {
gBrowser.pinTab(newTab);
}
// For some reason this doesn't seem to work :-(
if ( isSelected ) {
gBrowser.selectedTab = newTab;
}
// Swap tabs and remove placeholder-tab
gBrowser.swapBrowsersAndCloseOther(newTab, aTab);
}
};
This script is attempting to:
create a new folder
scan an InDesign document for all images
convert all images to grayscale in Photoshop
save new grayscale images in the new folder from Photoshop
Converting the images to grayscale in Photoshop requires the use of the BridgeTalk object, which allows for the communication between InDesign and Photoshop (the usage of the BridgeTalk object seems to be a form of Ajax).
What I have so far is almost working, being that a new folder is created, and InDesign does seem to be communicating with Photoshop via BridgeTalk. But when Photoshop is opened, nothing happens -- no new images are saved, and I'm not sure if the grayscale conversion is taking place or not...
Here is my code:
#target "InDesign"
var inDesignDocument = app.activeDocument;
var newFolder = createFolder(inDesignDocument); // if subdirectory images DNE, create this folder with the function below
sendImagesToPhotoshop(inDesignDocument, newFolder);
//---------------------------------------------------------------------------------------------------------------
function createFolder(doc)
{
try
{
/*
* type-casting the filePath property (of type object) into a String type;
* must be a String type to concatenate with the subdirectory variable (also of type String)
*/
var docPath = String(doc.filePath);
var subdirectory = "/BLACK AND WHITE IMAGES";
}
catch(e)
{
alert(e.message);
exit();
}
var imagesFolder = docPath + subdirectory; // concatenating the two variables
if(!Folder(imagesFolder).exists)
{
Folder(imagesFolder).create();
}
return imagesFolder; // for instantiation outside of this function
} // end of function createFolder
//---------------------------------------------------------------------------------------------------------------
function sendImagesToPhotoshop(doc, folder)
{
var imgs = doc.allGraphics;
var fileName = "";
var img = "";
var imgType = "";
for(var i = 0; i < imgs.length; i++)
{
if(imgs[i].itemLink != null)
{
fileName = imgs[i].itemLink.name;
img = new File(folder + "/" + fileName); // each image instantiated here
imgType = imgs[i].imageTypeName; // image type is determined here (.tif, .jpg, .png, etc..)
alert("The file \"" + fileName + "\"\n\tis a " + imgType + " file.");
// each image exported to the new folder here, by file type
switch(imgType)
{
case "GIF":
alert("This script cannot convert and export the GIF file:\n\t" + fileName + " !");
break;
case "JPG":
case "EPS":
case "PNG":
case "TIFF":
createBridgeTalkMessage(folder);
break;
default:
alert("\tUnlisted image type: " + imgType + "!\nAdd this type to the switch statement.");
break;
} // end of switch statement
} // end of if statement
} // end of for loop
} // end of function sendImagesToPhotoshop
//---------------------------------------------------------------------------------------------------------------
function createBridgeTalkMessage(imagesFolder)
{
var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = saveNewImageInPhotoshop.toSource() + "(" + imagesFolder.toSource() + ");";
bt.onError = function(e)
{
alert("Error: " + e.body);
}
bt.onResult = function(resObj){};
bt.send();
}// end of function createBridgeTalkMessage
//---------------------------------------------------------------------------------------------------------------
// called from function createBridgeTalkMessage
function saveNewImageInPhotoshop(imagePath)
{
var photoshopDoc = "";
app.displayDialogs = DialogModes.NO; // Photoshop statement, prevents status alerts from interrupting
photoshopDoc.changeMode(ChangeMode.GRAYSCALE); // convert image to GRAYSCALE
photoshopDoc.saveAs(new File(imagePath) );
photoshopDoc.close(SaveOptions.DONOTSAVECHANGES);
} // end of function saveNewImageInPhotoshop
This is based on the work of Kasyan Servetsky, found here: http://forums.adobe.com/message/3817782
Yeah I experienced issues recently with single line comments and indeed using /* ... */ did the trick. I think you can pass a string for your url but need to escape the slashes characters.
It seems you are passing a folder to Photoshop instead of an actual image file. That may probably explain your issue ;)
Loic