Script help: email images with a for loop

Discuss and share scripts and script files...
Post Reply
drewbrewit
Posts: 2
Joined: 19 May 2011 13:45

Script help: email images with a for loop

Post by drewbrewit »

I'm trying to write a script to email out a bunch of photos. I want the script to attach 1 image file (.jpg) per email message, for every image file I've selected in XYplorer.

The following script is close but includes every image I've selected on every email. How can I modify this script to give me just one image per email?

Code: Select all

 if (get("CountSelected")<1){end 1, "Please select at least one file first!<crlf>Script quits.";}

  //"SelectedItemsNames", [separator=CRLF], [pane=a]
  $filelist = get("SelectedItemsNames");

  //foreach($variable, listoftokens, [separator=|]) 
  foreach($MyNewVariable, $filelist, "<crlf>")
  {
//     msg $MyNewVariable,1;

    //Attach to Thunderbird
//Get item's path and names
    $items=chr(39).get("SelectedItemsPathNames",",").chr(39);
//Get item's names
    $itemnames=chr(39).get("SelectedItemsNames",", ").chr(39);
//Get item's Exif
    $itemexif=chr(39) . "Camera: " . property("Manufacturer", ) . " " . property("CameraModel", ) . " | " . "Exposure: " . property("ExposureTime", ) .  " sec. | " . "f/" . property("Aperture", ) . " | ISO: " . property("ISOspeed", ) . chr(39);
//Insert values into Thunderbird syntax
    $TB_Syntax= chr(34)."subject=$itemnames,body=$itemexif,attachment=$items".chr(34);

//Attach selected files to thunderbird's compose window
    run """c:\Program Files (x86)\Mozilla Thunderbird_v6\Thunderbird.exe"" -compose $TB_Syntax";
[/color]

Thanks.
~Nick

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Script help: email images with a for loop

Post by highend »

Code: Select all

$items=chr(39).get("SelectedItemsPathNames",",").chr(39);
You are including all selected items here...


This should work (but I didn't touch your itemexif variable):

Code: Select all

if (get("CountSelected")<1){end 1, "Please select at least one file first!<crlf>Script quits.";}

  //"SelectedItemsNames", [separator=CRLF], [pane=a]
  $filelist = get("SelectedItemsPathNames");

  //foreach($variable, listoftokens, [separator=|]) 
  foreach($MyNewVariable, $filelist, "<crlf>")
  {
//     msg $MyNewVariable,1;

    //Attach to Thunderbird
//Get item's path and names
    $items=chr(39).$MyNewVariable.chr(39);
//Get item's names
	$bs = strpos($MyNewVariable, "\", -1);
	$itemnames=chr(39).substr($MyNewVariable, $bs +1).chr(39);
//Get item's Exif
    $itemexif=chr(39) . "Camera: " . property("Manufacturer", ) . " " . property("CameraModel", ) . " | " . "Exposure: " . property("ExposureTime", ) .  " sec. | " . "f/" . property("Aperture", ) . " | ISO: " . property("ISOspeed", ) . chr(39);
//Insert values into Thunderbird syntax
    $TB_Syntax= chr(34)."subject=$itemnames,body=$itemexif,attachment=$items".chr(34);

//Attach selected files to thunderbird's compose window
    run """c:\Program Files (x86)\Mozilla Thunderbird_v6\Thunderbird.exe"" -compose $TB_Syntax";
One of my scripts helped you out? Please donate via Paypal

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script help: email images with a for loop

Post by Stefan »

Hi Nick,

first step of an answer:

If your $filelist holds all file names,
then in the foreach loop one over the other file name is stored into your $MyNewVariable var.

use smtg like:

Code: Select all

  $filelist = get("SelectedItemsPathNames");

  foreach($MyNewVariable, $filelist, "<crlf>"){
     $item = $MyNewVariable;
     $itemname = gettoken($item, -1, "\");
     $itemexif = property( "size", $item);
     //$itemexif = $itemexif . property( "other property", $item);
     //$itemexif = $itemexif . property( "other property", $item);
     

     msg "$item<crlf>$itemname<crlf>$itemexif";

     //Insert values into Thunderbird syntax

     //Attach selected files to thunderbird's compose window

 }

drewbrewit
Posts: 2
Joined: 19 May 2011 13:45

Re: Script help: email images with a for loop

Post by drewbrewit »

Thanks for the help! I've got it working. Thanks for being so helpful.

Post Reply