selectitems usage for looping through the selected filelist

Discuss and share scripts and script files...
scribbly
Posts: 17
Joined: 03 Jan 2012 13:20
Location: Australia
Contact:

selectitems usage for looping through the selected filelist

Post by scribbly »

I'm just trialing XYplorer after using the free version what seems like years ago.

Current problem is I'm working with photos with EXIF data, but XYplorer does not support EXIF data in the listview (which is a big shame). Anyway, I'm editing my photos that I've copied to a working area, but I need to sort them based on Original Creation Date.

I found others' efforts here in getting a work-around, which is acceptable: ie to copy the EXIF OriginalCreationDate into the Created Date using the <dateexif> function.

Now my problem is with processing whole folders. I've got the following script in the Catalogue area, but the selectitems function does not seem to function as expected? What happens if I have many selected is that only the OriginalCreationDate of the first file is used for all the others: I would have expected that selecteditems would select the next as if by the mouse... but that does not seem to be the case??

Code: Select all

$a = get("SelectedItemsPathNames", "|"); 
 foreach($item,$a,"|") {
 if($item == "") {break; }
 selectitems $item , 0 , 0;
 timestamp m c , <dateexif> , $item;
 }
Any ideas?

admin
Site Admin
Posts: 66274
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: selectitems usage for looping through the selected filel

Post by admin »

Hi and welcome,

this command is already available as a No-GUI command here: CKS / Miscellaneous / Timestamp / Set Created Date to EXIF Date

If you need further support in this, say so.

Don

scribbly
Posts: 17
Joined: 03 Jan 2012 13:20
Location: Australia
Contact:

Re: selectitems usage for looping through the selected filel

Post by scribbly »

admin wrote:Hi and welcome,

this command is already available as a No-GUI command here: CKS / Miscellaneous / Timestamp / Set Created Date to EXIF Date

If you need further support in this, say so.
Thanks... that was easy!!

Just to satisfy my curiosity: why didn't the selectitems function in the script work like I thought?

and to satisfy yet to be realised needs: are there plans to support EXIF metadata in the interface?

admin
Site Admin
Posts: 66274
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: selectitems usage for looping through the selected filel

Post by admin »

scribbly wrote:
admin wrote:Hi and welcome,

this command is already available as a No-GUI command here: CKS / Miscellaneous / Timestamp / Set Created Date to EXIF Date

If you need further support in this, say so.
Thanks... that was easy!!

Just to satisfy my curiosity: why didn't the selectitems function in the script work like I thought?

and to satisfy yet to be realised needs: are there plans to support EXIF metadata in the interface?
1. No time to check.
2. Yes.
:)

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: selectitems usage for looping through the selected filel

Post by TheQwerty »

scribbly wrote:Just to satisfy my curiosity: why didn't the selectitems function in the script work like I thought?

Code: Select all

$a = get("SelectedItemsPathNames", "|");
foreach($item,$a,"|") {
if($item == "") {break; }
selectitems $item , 0 , 0;
timestamp m c , <dateexif> , $item;
}
This doesn't work as you expected because "<dateexif>" returns the value for the currently selected AND focused list item, and when you change the selection with "selectitems" you're using "0" for the "focusfirst" argument which tells XY to not move the focus.

There's a few ways to fix this:
  • Change the focus & selection with selectitems:

    Code: Select all

    // Replace
    selectitems $item, 0, 0;
    // with
    selectitems $item, 0, 1;
  • Instead of using "selectitems" and "<dateexif>" you could retrieve the EXIF data using:

    Code: Select all

    Property("WhenTaken", $item); //Correct property name depends on OS & Language
    This is nice because you can use it without changing the current selection/focus, but I'm not 100% sure if this will give you a date format that can be used by "timestamp" directly.
  • EDIT: You could also take a more complex approach and instead of using Get("SelectedItemPathNames") to retrieve the current selection - use Report("{Fullpath}|{WhenTaken}<crlf>", 1); to retrieve both the paths and the EXIF data at once, and loop over the lines and use GetToken for the fields. However, according to the help this may not work after XP.
If you've got more questions feel free to ask! :D

scribbly
Posts: 17
Joined: 03 Jan 2012 13:20
Location: Australia
Contact:

Re: selectitems usage for looping through the selected filel

Post by scribbly »

TheQwerty wrote: This doesn't work as you expected because "<dateexif>" returns the value for the currently selected AND focused list item, and when you change the selection with "selectitems" you're using "0" for the "focusfirst" argument which tells XY to not move the focus.
Awesome: my misunderstanding of the Help File: "EXIF date of the current list item"

Thanks for the suggestions: definitely helped my understanding :)

In the end (maybe short term) I used Don's suggestion:
admin wrote: this command is already available as a No-GUI command here: CKS / Miscellaneous / Timestamp / Set Created Date to EXIF Date
and just changed the script to

Code: Select all

#1074;
which does what I want (and keeps the selection).

Thanks again!

admin
Site Admin
Posts: 66274
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: selectitems usage for looping through the selected filel

Post by admin »

scribbly wrote:...and just changed the script to

Code: Select all

#1074;
I admire the tight logic of your scripting. ;)

scribbly
Posts: 17
Joined: 03 Jan 2012 13:20
Location: Australia
Contact:

Re: selectitems usage for looping through the selected filel

Post by scribbly »

admin wrote:
scribbly wrote:...and just changed the script to

Code: Select all

#1074;
I admire the tight logic of your scripting. ;)
Well... it was commented too, but I moved the comment to the title to reduce duplication ;)

scribbly
Posts: 17
Joined: 03 Jan 2012 13:20
Location: Australia
Contact:

Re: selectitems usage for looping through the selected filel

Post by scribbly »

admin wrote:
scribbly wrote:...and just changed the script to

Code: Select all

#1074;
I admire the tight logic of your scripting. ;)
All is going well... I'm managing to tag my graphics with GPS Exif tags and Date Exif tags based on the original photos, but when I get to writing the Original Date from the Exif DateTimeOrinal I get a requester that I don't really want:

Code: Select all

focus;
  END (<curitem>=="", "Select one file to compare with");
  $source= <curitem>; 

  focus pi;

  $pane2files = get("SelectedItemsPathNames", "|");
  $destination = "";
  foreach($token,$pane2files,"|") {
  	$destination = $destination . quote($token);
  }

  $items= getinfo ("CountItems");
  END ($items==0);

  run """C:\Program Files (x86)\ExifTool\exiftool.exe"" -TagsFromFile ""$source"" -GPS:All -DateTimeOriginal -DateTimeDigitized $destination -v2",,1;
  #1074; // Set Modified date to DateTimeOriginal
Question: Is there a way to turn off the requester that #1074 pops up?

admin
Site Admin
Posts: 66274
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: selectitems usage for looping through the selected filel

Post by admin »

requester? Not sure what you mean.

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

Re: selectitems usage for looping through the selected filel

Post by highend »

Probably the confirmation window...
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 66274
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: selectitems usage for looping through the selected filel

Post by admin »

highend wrote:Probably the confirmation window...
But #1074; has none. :?

It has a "success" feedback, but this is not meant by "requester" I think.

scribbly
Posts: 17
Joined: 03 Jan 2012 13:20
Location: Australia
Contact:

Re: selectitems usage for looping through the selected filel

Post by scribbly »

admin wrote:
highend wrote:Probably the confirmation window...
But #1074; has none. :?

It has a "success" feedback, but this is not meant by "requester" I think.
Yes.. sorry for the language:
see attached image.

Is there a way to turn this off?
To see the attached files, you need to log into the forum.

admin
Site Admin
Posts: 66274
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: selectitems usage for looping through the selected filel

Post by admin »

Nope, no way I'm afraid. Don't you like the feedback? Where's the problem?

scribbly
Posts: 17
Joined: 03 Jan 2012 13:20
Location: Australia
Contact:

Re: selectitems usage for looping through the selected filel

Post by scribbly »

admin wrote:Nope, no way I'm afraid. Don't you like the feedback? Where's the problem?
Well, I do... and I think it's important too... it's just when you've got a stack of photos to do it's an extra click I would have preferred not to do.

The information also duplicates what I can see in the list: I can see the change happening.

So... not a problem... more a preferrence :D

Post Reply