• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Copy sort order between folder

New Here ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

Hello,

I'd like to copy sort orders from one folder to another. Let's say one folder contains RAW files and the other JPEGs with identical names.

Should be easy to copy the .BridgeSort file and modify the content, that is the file extension of the key value of the item tags. But the key is build by the filename plus something that seems to be a timestamp. I just can't figure out what timestamp from metadata or file attributes I have to use.

Rainer

TOPICS
Scripting

Views

1.1K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jun 14, 2019 Jun 14, 2019

#target bridge;

//

//Run this script from ExtendScript Toolkit

//Example of date time string used in .BridgeSort

//requires you select at least one file

//

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

var DT = new XMPDateTime(app.document.selections[0].spec.created).toString().replace(/-|T|:|Z/g,"");

alert("<item key='" + decodeURI(app.document.selections[0].spec.name) + DT + "' />");

Likes

Translate

Translate
Community Expert ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

ScriptUI has operators for sort order. I have been playing with them and have only gotten them to partially work but that would be your best bet.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

The sorts that are available are:-

app.document.sorts = [{ type:"string",name:"name", reverse:false }]; //Sort by FileName

app.document.sorts = [{ type:"string",name:"document-kind", reverse:false }]; //Sort by Type

app.document.sorts = [{ type:"date",name:"date-created", reverse:false }]; //Sort by Date Created

app.document.sorts = [{ type:"date",name:"date-modified", reverse:false }]; //Sort by Date Modified

app.document.sorts = [{ type:"number",name:"file-size", reverse:false }]; //Sort by Size

app.document.sorts = [{ type:"dimensions",name:"dimensions", reverse:false }]; //Sort by Dimensions

app.document.sorts = [{ type:"resolution",name:"resolution", reverse:false }]; //Sort by Resolution

app.document.sorts = [{ type:"colorProfile",name:"color-profile", reverse:false }]; //Sort by Color Profile

app.document.sorts = [{ type:"string",name:"label", reverse:false }]; //Sort by Label

app.document.sorts = [{ type:"number",name:"rating", reverse:false }]; //Sort by Rating

app.document.sorts = [{ type:"string",name:"keywords", reverse:false }]; //Sort by Keywords

app.document.sorts = [{ type:"date",name:"user", reverse:false }]; //Sort Manually

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

#target bridge;

//

//Run this script from ExtendScript Toolkit

//Example of date time string used in .BridgeSort

//requires you select at least one file

//

if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

var DT = new XMPDateTime(app.document.selections[0].spec.created).toString().replace(/-|T|:|Z/g,"");

alert("<item key='" + decodeURI(app.document.selections[0].spec.name) + DT + "' />");

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

Thanks for all your suggestions.

@SuperMerlin:

That's exactly the way I'd like to do it, but it's still not the date that is in key of the .BridgeSort file,

As an example, my -BridgeSort shows the following lines:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>

<dirinfo>

<files>

<item key='5D_L0218.CR220180923184225' />

<item key='5D_L0561.CR220180923183949' />

<item key='5D_L0562.CR220180923183949' />

<item key='5D_L0565.CR220180923183948' />

And that is excatly the sort order of the Bridge UI. So for the first file I would assume to find a date like 2018-09-23 somewhere. Your script with the created timestamp returns

1.JPG

That seems to be the creation date of the file as it is given by the file system (folder is copied, that's why all dates are nearly equal):

2.JPG

When I open the XMP file into an editor an do a search for 2018-09-23 (or even only 2018) I can't find a single reference for that date. The closest match is the "date modified" of the RAW file. But that date is off 21h 43m - so that's not a timezone difference.

Yet Bridge is able to put the files in the right order.

Rainer

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

Strange I wasn't getting the +0100

The date time if from the files date created in the format  YYYYMMDDHHMMSS

So if you are getting the extra characters they could be removed very easily.

The:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>

<dirinfo>

<files>

etc. are standard so you would just write these lines out to the file.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

I think that's because my system was at CET not UTC when the file was created, the time offset is +1h. That would be easily fixed by converting to UTC.

What has made me wondering, was that sorting still worked after copying the folder. After copying the content of the .BridgeSort is unchanged but all files have new values for "date created" but sort order in the UI is still correct. I have then deleted the .BridgeSort and created an new sort order in the UI. I can confirm that for the key value the "date created" is then used. To find out why the sorting was preserved I have simply replaced the timestamp in the key value with 19000101000000 and found the sort order ist still correct. I think the timestamp is in the key value in case the Bridge window is set to show the content of folders and subfolders. In that case there can be files with identical file name - so they can only be distinguished by the date of creation. I still wonder what will happen in that case when you make a copy with an existing .BridgeSort file but I am to lazy to try it. I don't have to take care of that for the purpose of my script.

Thanks again,

Rainer

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 14, 2019 Jun 14, 2019

Copy link to clipboard

Copied

Another idea might be to just read in the old .BridgeSort and do a global replace of cr2 to jpg

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2019 Jun 16, 2019

Copy link to clipboard

Copied

From what I have seen that would work. But because of my workflow there might be different versions of one files in the destination folder (filename_1, filename_2 ...) I have opted to go the long way and iterate through the original .BridgeSort to find all corresponding files (filename*.*). and get their crreation date.

BTW: to use the conversion from javascript date to XMPDateTime is really great! Saves a lot of pain from the work with the date type.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 16, 2019 Jun 16, 2019

Copy link to clipboard

Copied

LATEST

That's what I have ended up with. Maybe it can be helpful for somebody - although I know there's a lot room for improvements

function BridgeCopySortOrder() {

#target bridge

var sUsageDescription = "Kopiert die Sortierfolge aus einem auszuwählenden Quellverzeichnis in ein Zielverzeichnis.\rDie Soritierung berücksichtigt alle in der Quellsortierung vorkommenden Dateiname mit bliebigen Dateitypen und Namenserweiterungen (<Dateiname>*.*)\r" +

                                        "bei gleichen Dateinamen (inkl. Dateinamenserweiterung) erfolgt die Sortierung anhand des Erstellungsdatums\rDateien, deren Namen nicht in der Quellsortierung erhalten sind, werden an das Ende gestellt";

                                      

var sSortFileHeader = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n<dirinfo>\n<files>\n";

var sSortFileFooter = "</files>\n</dirinfo>";

var sSortLineStart = "<item key='";

var sSortLineEnd = "' />";

if (ExternalObject.AdobeXMPScript == undefined) {

    ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

}

app.bringToFront();

app.synchronousMode = true;

alert(sUsageDescription);

var fldrSortFile = new Folder();

var fldrDestination = new Folder();

f  = fldrSortFile.selectDlg("Ordner mit manueller Sortierfolge");

if (f != null) {

    var arrFileSortOrder = f.getFiles(".BridgeSort");

    if (arrFileSortOrder.length>0) {

        f =  fldrDestination.selectDlg("Ordner mit zu sortierenden Elementen");

        if (f != null) {

            arrFileSortOrder[0].open ('r');

            sSort = arrFileSortOrder[0].read ();

            arrFileSortOrder[0].close();

            var arrSortFileLines = sSort.split('\n');

            var sNewSortFile = "";

            for  (var nCount1 = 0; nCount1 < arrSortFileLines.length; ++nCount1)  {

                if (arrSortFileLines[nCount1].substr(0, sSortLineStart.length)==sSortLineStart) {

                    var sFileName = arrSortFileLines[nCount1].slice(sSortLineStart.length, arrSortFileLines[nCount1].lastIndexOf ("."));

                    var arrFilesWithSameName = f.getFiles(sFileName + "*.*");

                    if (arrFilesWithSameName.length>0) {

                        arrFilesWithSameName.sort(function(a, b) {return a.created- b.created;})

                        for  (var nCount2 = 0; nCount2 < arrFilesWithSameName.length; ++nCount2)  {

                            sTimestampFileCreated = new XMPDateTime(arrFilesWithSameName[nCount2].created).toString().replace(/-|T|:|Z/g,"");

                            if (sTimestampFileCreated.indexOf("+") >= 0) {

                                sTimestampFileCreated = sTimestampFileCreated.substring(0, sTimestampFileCreated.indexOf("+"));

                                }

                            sSortLine = sSortLineStart + decodeURI(arrFilesWithSameName[nCount2].name) + sTimestampFileCreated + sSortLineEnd + '\n';

                            sNewSortFile = sNewSortFile + sSortLine;

                            }

                        }

                    }

                }

            if (sNewSortFile != "") {

                sNewSortFile = sSortFileHeader + sNewSortFile + sSortFileFooter;

                var arrFileSortOrder = f.getFiles(".BridgeSort");

                if (arrFileSortOrder.length>0) {

                    arrFileSortOrder[0].remove();

                    }

                var fNewSortFile = new File(f.fullName + "/.BridgeSort");

                fNewSortFile.open('a');

                fNewSortFile.write(sNewSortFile);

                fNewSortFile.close();

                fNewSortFile.hidden = true;

                }

            }

        }

    else {

        alert("Gewählter Ornder enthält keine Datei .BridgeSort");

        }

    }

app.synchronousMode = false;

}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines