Renaming files using favoriteExecute does not work

Started by gangenen, September 09, 2017, 10:05:00 PM

Previous topic - Next topic

gangenen

I am trying to rename files using favoriteExecute but my code does not seem to have any effect. I used favoriteExecute also for applying a metadata template - and there it worked fine.

When I click on the favorite from within IMatch then it renames the files instantly. But the code below does not seem to do anything:


                    response.files.forEach(function(f) {
                        console.log('Rename: ' + f.fileName + ' ' + f.id);
                        IMatch.favoriteExecute({
                            guid: 'A56C78A9-7874-4648-B864-E2B293934DBD',
                            op: 'primary',
                            id: f.id
                        });


Information on the favorite:

        {
          "id": "A56C78A9-7874-4648-B864-E2B293934DBD",
          "type": "renamer",
          "name": "Date and Time (Georg)",
          "description": "",
          "backgroundColor": "#008000"
        },


Any idea what could be the problem?

Regards,

Georg

Mario

You call favoriteExecute in a loop. This is an asynchronous function which means that you are running a favorite several times at the same time, trying to rename several files at the same time. This may just be impossible.

Did you check the response from IMWS?
Did you check the IMatch log file for warnings or errors?

The ability to execute Favorites from apps has limitations. Favorites are primarily designed for interactive use, not to be run multiple times asynchronously from apps.
Why don't you use the file rename features including in IMWS instead?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

gangenen

Thanks for your answer.
I did not realize that I could check the response the same way as for other functions. I now changed the code to do this and also to call it with an idlist rather than iterative:


               //Get list of favorites-for debugging
                IMWS.get('v1/imatch/favorites/list', {
                }).then(function(response) {
                    console.log(response);
                    console.log(JSON.stringify(response,null,2));
                });

                //Check selected files - for debugging
                IMWS.get('v1/files', {
                    idlist: IMatch.idlist.fileWindowSelection,
                }).then(function(response) {
                    console.log(response)
                });
               
                console.log('Rename files')
               //Apply Renamer with preset "Date and Time (Georg)"
               IMatch.favoriteExecute({
                    guid: 'A56C78A9-7874-4648-B864-E2B293934DBD',     
                    op: 'primary',
                    idlist: IMatch.idlist.fileWindowSelection
                }).then(function(response) {
                    console.log('Response from calling renaming favorite');
                    console.log(response);
                    console.log(JSON.stringify(response,null,2));
                });



The response for  IMatch.favoriteExecute is:


    {
      "result": "ok"
    }


I set the IMatch log level to debug and ran the app. I do not understand the log but it does not seem to indicate an error:


09.10 12:48:29+    0 [22E0] 50  M>  <  1 PTDataGrouperManager::GetGroups
09.10 12:48:35+ 6219 [2A18] 50  M>  >  1 CIMatchIMWS::HandlerGET_UserInfo  'IMWS\IMatchIMWS.cpp(504)'
09.10 12:48:35+    0 [2A18] 50  M>  <  1 CIMatchIMWS::HandlerGET_UserInfo
09.10 12:48:35+   62 [2234] 50  M>  >  1 CIMatchWebServices::HandlerGET_Files  'IMatchWebServices.cpp(7657)'
09.10 12:48:35+    0 [29F0] 50  M>   >  2 CIMatchIMWS::HandlerGET_Favorites  'IMWS\IMatchIMWS.cpp(2471)'
09.10 12:48:35+    0 [2234] 10  M>    >  3 PTMetabase::GetGPSCoordinates  'PTMetabase2.cpp(2286)'
09.10 12:48:35+    0 [2234] 10  M>    <  3 PTMetabase::GetGPSCoordinates
09.10 12:48:35+    0 [29F0] 10  M>    >  3 CIMEngine5::GetFavoriteSets  'IMEngine5.cpp(9850)'
09.10 12:48:35+    0 [29F0] 10  M>    <  3 CIMEngine5::GetFavoriteSets
09.10 12:48:35+    0 [29F0] 10  M>    >  3 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+   16 [29F0] 10  M>    <  3 [16ms] CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [29F0] 10  M>    >  3 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [29F0] 10  M>    <  3 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [29F0] 10  M>    >  3 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [29F0] 10  M>    <  3 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [29F0] 10  M>    >  3 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [29F0] 10  M>    <  3 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [29F0] 10  M>    >  3 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [29F0] 10  M>    <  3 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [29F0] 10  M>    >  3 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [29F0] 10  M>    <  3 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [2234] 50  M>   <  2 [16ms] CIMatchWebServices::HandlerGET_Files
09.10 12:48:35+    0 [133C] 50  M>   >  2 CIMatchIMWS::HandlerPOST_FavoriteExecute  'IMWS\IMatchIMWS.cpp(2566)'
09.10 12:48:35+    0 [133C] 10  M>    >  3 CIMEngine5::GetFavoriteSets  'IMEngine5.cpp(9850)'
09.10 12:48:35+    0 [29F0] 50  M>    <  3 [16ms] CIMatchIMWS::HandlerGET_Favorites
09.10 12:48:35+    0 [133C] 10  M>   <  2 CIMEngine5::GetFavoriteSets
09.10 12:48:35+    0 [133C] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [133C] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [133C] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [133C] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [133C] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [133C] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [133C] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [133C] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [133C] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [133C] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [133C] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [133C] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [037C] 10  M>   >  2 CIMatchWebServices::Authenticate  'IMatchWebServices.cpp(16514)'
09.10 12:48:35+    0 [037C] 05  M>    >  3 CIMatchWebServices::ValidateUser  'IMatchWebServices.cpp(2886)'
09.10 12:48:35+    0 [037C] 05  M>    <  3 CIMatchWebServices::ValidateUser
09.10 12:48:35+    0 [037C] 10  M>    >  3 CIMatchWebServices::CreateSession  'IMatchWebServices.cpp(16626)'
09.10 12:48:35+    0 [037C] 10  M>    <  3 CIMatchWebServices::CreateSession
09.10 12:48:35+    0 [037C] 10  I>   Authenticated
09.10 12:48:35+    0 [037C] 10  M>   <  2 CIMatchWebServices::Authenticate
09.10 12:48:35+    0 [3284] 10  M>   >  2 CIMEngine5::GetFavoriteSets  'IMEngine5.cpp(9850)'
09.10 12:48:35+   15 [3284] 10  M>   <  2 [15ms] CIMEngine5::GetFavoriteSets
09.10 12:48:35+    0 [3284] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [3284] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [3284] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [3284] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [3284] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [3284] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [3284] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [3284] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [3284] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [3284] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [3284] 10  M>   >  2 CIMEngine5::GetFavoriteSet  'IMEngine5.cpp(9872)'
09.10 12:48:35+    0 [3284] 10  M>   <  2 CIMEngine5::GetFavoriteSet
09.10 12:48:35+    0 [3284] 10  M>   >  2 CIMTaskFavorites::ProcessShortcut  'IMTasksFavorites.cpp(603)'
09.10 12:48:35+    0 [3284] 10  M>   <  2 CIMTaskFavorites::ProcessShortcut
09.10 12:48:35+    0 [3284] 10  M>   >  2 PTTaskManager::Add  'PTTaskManager.cpp(75)'
09.10 12:48:35+    0 [3284] 10  M>   <  2 PTTaskManager::Add
09.10 12:48:35+    0 [133C] 50  M>  <  1 [15ms] CIMatchIMWS::HandlerPOST_FavoriteExecute
09.10 12:48:39+ 3703 [22E0] 50  M>  >  1 PTDataGrouperManager::GetGroups  'PTDataGrouperManager.cpp(169)'
09.10 12:48:39+    0 [22E0] 50  M>  <  1 PTDataGrouperManager::GetGroups



For completeness, I also added a screenshot of the renamer preset that the app is calling.

The reason I am trying to call the renamer is its simplicity. I have the preset configured that works for me and I do not need to check for any file-name collisions etc. that I would need to do if I renamed the files directly from the script. When I looked at the renaming function I read that I would need to do this. Or is there a simple way to handle this?

One question on calling the function favoriteExecute. If I add my code into the function like this:


               IMatch.favoriteExecute({
                    guid: 'A56C78A9-7874-4648-B864-E2B293934DBD',     
                    op: 'primary',
                    idlist: IMatch.idlist.fileWindowSelection
                }).then(function(response) {

                    <my code comes here>

                });


then this would only be executed when the favoriteExecute function has been completed. Can I then rely that the renaming is complete or that a metadata-template has been applied to all? The reasons for asking is that I would like then to call e.g. Geosetter and the names should not change anymore after the call.

Georg

Mario

#3
Renamer Favorites are not supported by this feature. I just checked.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mario

Just not implemented. I'll include that for the next release.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

gangenen

Thanks. I will re-check my approach and probably implement the renaming anyway in the script. As you say, my naming scheme is simple.

Just one more question on function-calls in general: Can I trust that a call has been completed when I get a promise returned (for other functions than favoriteExecute). Or is it in general a problem that a function might not be completed by the time I get a promise?

/Georg

Mario

This depends on the endpoint. Some endpoints trigger background activity, for example. Doing a simple thing as changing a keyword can trigger all kinds of activity. Same for copying, moving, renaming files. All this can affect background rescans, data-driven categories, trigger other apps which monitor for certain events etc.

Rescanning a folder requires several steps. Only the first step is done when the endpoint returns.

Things like that.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook