Author Topic: Randomize keyword order  (Read 907 times)

wout

  • Newbie
  • *
  • Posts: 7
Randomize keyword order
« on: April 05, 2018, 11:06:47 PM »
Hello,

I was wondering if there is a way to take the existing keywords of a (JPG) file and randomize their order.

I wish the keyword order is no longer alphabetical but random.

Would this be possible with exiftool?

Thanks!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16724
    • ExifTool Home Page
Re: Randomize keyword order
« Reply #1 on: April 06, 2018, 07:14:02 AM »
Sure.  This could more easily be done with a user-defined Composite tag, but as a one-liner:

exiftool "-keywords<${keywords;my @a=split m(//);my @b;push @b, splice(@a,int(rand(@a)),1) while @a;$_=\@b}" -sep // FILE

Use Subject instead of Keywords if you are using XMP keywords instead of IPTC/NAA.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

wout

  • Newbie
  • *
  • Posts: 7
Re: Randomize keyword order
« Reply #2 on: April 06, 2018, 07:58:17 PM »
Hi Phil,

Thanks so much for your time!

I tried the script in various ways but I get a 'bad substitution' return. Does it work on your end?

P.S. I have already successfully run exiftool "-Title>Description", but that is a much simpler code!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16724
    • ExifTool Home Page
Re: Randomize keyword order
« Reply #3 on: April 07, 2018, 06:30:17 AM »
It worked for me.  Are you on Windows?  If not, you must change to single quotes.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

wout

  • Newbie
  • *
  • Posts: 7
Re: Randomize keyword order
« Reply #4 on: April 08, 2018, 12:13:52 AM »
It works with the single quotes! I'm on mac indeed. So happy. Thanks for all the work you put into this software, it really helps to organise my files.