Skip to main content
Inspiring
August 11, 2018
Question

Is it possible to script the 2018 share feature to send email?

  • August 11, 2018
  • 2 replies
  • 530 views

I'm just wondering if scripts have access to the share feature and if so how to call it? I'm would like to set up a email once I'm done processing a file.

Thanks!

This topic has been closed for replies.

2 replies

Silly-V
Legend
August 13, 2018

I've been able to get some results like this on Windows by using AutoHotKey & VBS, triggered from AHK to run the jsx and then run a VBS to get the data and make an Outlook email with attachments, etc. However it was a rather crude way - and I didn't have to use it very often so it didn't get much chance for refinement - as I passed data among the things via .txt files.

I'm sure the JJMack way here is the best way to do it from inside the jsx. In Windows there's a great advantage to being able to write BAT or VBS files and execute them from inside jsx.

On Macs, it's a little different because file.execute() on applescript files doesn't run them, just opens them up in a Script Editor app. But no worries! Because it's easy to set up folder action applescripts which act on files dropped into those folders, an applescript could be triggered via simply dropping a .txt file with instructions into a folder and letting the AS run based on them. As an even faster alternative, it's possible to make an 'executor.app' application whose sole purpose is to run a .scpt file. Then you write the .scpt applescript from inside the jsx and do file.execute() on the executor.app application. This effectively replicates the Windows features as far as being able to write a script from another program and run it.

JJMack
Community Expert
Community Expert
August 13, 2018

I have never attempted to open a port connection to send an  e-mail composed a script to a mail server or automate any share feature.  However, Scripts can start local application and I have  sent e-mail that way in a Photoshop script.  I use Thunderbird as my e-mail client yes I'm an old fart.  Anyway if the current document has been saved it has a backing file that can be sent in an e-mail.  So all my script does is check to see if there is a backing file and if there is the script prompts me the Photoshop user to enter an e-mail address. The the script start  thunderbird passing the e-mail address, the subject: the file you requested, body the backing file's path and file name on my machine and attachments the backing file and my signature file.

Thunderbird Windows open  I can add any addition information and e-mail addresses I want into the e-mail and send it off.

If you are editing an old image and have made changes  make sure you save the current document over the backing file for its the dcument backing file that is e-mailed not the current open document in memory.

The script is quite like Photoshop Share e-mail.  However Photoshop Share can sent unsaved current documents as a jpg. Like my script it prompts for an e-mail address once set up so you do not need a script like mine unless you want to send other file types like png psd or jpeg with a dpi resolution setting.  My script sends the saved document.  Clicking share is like my script its interactive you need to set the e-mail address finish the e-mail and send.   I do not know if you can script share and make share none interactive.

Why do you want to or need to script Photoshop share?

The Scriptlistner plug-in only records this for share:

// =======================================================

var idtoggleQuickShare = stringIDToTypeID( "toggleQuickShare" );

    var desc571 = new ActionDescriptor();

    var idShw = charIDToTypeID( "Shw " );

    desc571.putBoolean( idShw, true );

executeAction( idtoggleQuickShare, desc571, DialogModes.NO );

It does not work if use in a script:

My script looks something like this Jive  or copy paste, tabs, ]messes with the text formatting

/* ==========================================================

// 2014  John J. McAssey (JJMack)

// ======================================================= */

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

/* Help Category note tag menu can be used to place script in automate menu

<javascriptresource>

<about>$$$/JavaScripts/email/About=JJMack's email .^r^rCopyright 2014 Mouseprints.^r^rScript email active document if saved</about>

<category>JJMack's Script</category>

</javascriptresource>

*/

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

// ensure at least one document open

if (!documents.length) alert('There are no documents open.', 'No Document');

else {

// declare Global variables

main(); // at least one document exists proceed

}

///////////////////////////////////////////////////////////////////////////////

//                            main function                                  //

///////////////////////////////////////////////////////////////////////////////

function main() {

// declare local variables

var orig_ruler_units = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS

try {code();}

catch(e) {alert(e + ': on line ' + e.line, 'Script Error', true);} // display error message if something goes wrong

app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings

}

///////////////////////////////////////////////////////////////////////////////

//                           main function end                               //

///////////////////////////////////////////////////////////////////////////////

function code() {

var to="";

//var to="jjmacks@hotmail.com";        // Bypass prompt and send home

var cc="";

var cc="jjmacks@hotmail.com";        // Copy Myself

var att = "";                        // declare attachment var                        

try {att=decodeURI(app.activeDocument.fullName);}

catch(e) {alert("Document " + app.activeDocument.name + " needs to be saved"); return;}

if (!app.activeDocument.saved) {alert("Document " + app.activeDocument.name + " needs to be saved"); return;}

   

var testatt = new File(att);                                                                // Test if backing file still exists

  if(testatt.exists){                                                                         // convert full file name and path to windows standard form

att = att.replace("/","");                                                              // Strip off leading "/" or the one after the leading "~"

if (att.substr(0,1)== "~" ) {att=att.replace("~", $.getenv("USERPROFILE") +"\\");}      // user space

else {att = att.replace("/",":\\");}                                                    // Device root :\\

while (att.indexOf("/")!=-1 ) { att = att.replace("/","\\"); }                          // Replace "/" with "\" need two to get one

if (to=="") {to=prompt("Enter email address",to);}                                      // Prompt for email address if no default

if (to!="" && to!=null) {emailer(to,cc,att);}                                           // If addressed emails current document backing file

}

else{alert('File = "' + att +'" not found');}

}

///////////////////////////////////////////////////////////////////////////////

//                                emailer  function                          //

///////////////////////////////////////////////////////////////////////////////

function emailer(to,cc,file){

var pgm = "C:\\Program Files (x86)\\Mozilla Thunderbird\\thunderbird.exe";

var mailer = new File(pgm);

  if(!mailer.exists){alert("Unable to find Thunderbird\rYou will need to modify Emailer.jsx\rand correct the path"); return; }

//thunderbird -compose "to='john@example.com,kathy@example.com',cc='britney@example.com',subject='dinner',body='How about dinner tonight?',attachment='C:\temp\info.doc,C:\temp\food.doc'"

var option ="";

option += " -compose";

option += ' "';

option += "to='"

option += to;

option += "'";

if(cc!="") {

option += ",cc='"

option += cc;

option += "'";

}

option += ",subject='" ;

option +=  "The file you requested" ;

option += "'";

option += ",body='";

option +=  file ;

option += "'";

option += ",attachment='";

option +=  file ;

var file2 = "E:\\My Files\\Pictures\\JJMack.png";

option +=  "," + file2 ;

option += "'";

option +='"';

//alert('app.system("CMD /Q /C Start "Thunderbird" /B /MIN "' + pgm + '" '  + option);

//app.system('CMD /Q /C Start "Thunderbird" /B /MIN "' + pgm + '" '  + option );

//alert('app.system(Start "Thunderbird" /B /MIN "' + pgm + '" '  + option);

app.system('Start "Thunderbird" /B /MIN "' + pgm + '" '  + option );

/*

var batch_file = new File(Folder.temp + "/send_email.bat");

batch_file.open("w");

//alert('"Start "Thunderbird" /B /MIN "' + pgm + '" '  + option);

batch_file.write('Start "Thunderbird" /B /MIN "' + pgm + '" '  + option );

batch_file.close;

batch_file.execute();

*/

};

JJMack