GeoSetter app: Open selected files in GeoSetter

Started by axel.hennig, June 01, 2017, 10:33:31 PM

Previous topic - Next topic

axel.hennig

Hello,

please find attached my first IMatch 2017 app.

The app opens all selected files in GeoSetter (GeoSetter in collection-mode).

If you want to try this app you have to adapt the lines 28 and 30 in index.html. Then, copy all three files (app.json, geosetter.png and index.html) to a new folder geosetter under C:\ProgramData\photools.com\imatch6\webroot\user.

The app is not very nice programmed since it has the disadvantage that it needs a batch-file and that there is a timeout of 2 seconds. The timeout is needed since JavaScript runs asynchronous (as Mario explained in detail in this post). Mario also describes a solution in his post, but at the moment that's too complicated for me. Maybe someone else can help me to improve this app.

Axel

Update: The new version (1.1) doesn't need a batch file anymore and the "timeout" problem is also solved.

Mario

Congrats!

Why do you need a batch file?
I don't know anything about how GeoSetter can be used from the command line. Usually drag  & drop should work?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

axel.hennig

In the actual version the batch file is gone.

At the moment I'm using setTimeout to wait 2sec until the params file (needed by GeoSetter) is fully written. But I can't figure out how to work with these asynchronous things. I just want that GeoSetter is called AFTER the params file is created completely... maybe tomorrow.


<script>

    var geosetter = 'C:\\Programme\\GeoSetter\\GeoSetter.exe';
    var geosetterparam = 'D:\\imatch_geosetter_params.txt';

    $(document).ready(function () {
       
        IMatch.writeTextFile({
        filename: geosetterparam,
        data: '/COLLECTION\r\n'
        });
       
        IMWS.get('v1/files',{
            // This idlist represents all files currently selected in the active file window.
            idlist: IMatch.idlist.fileWindowSelection,
            // we only need the file name
            fields: 'filename'
        }).then(function(response) {
            // For all files returned...
            for (var f = 0; f < response.files.length; f++) {
                IMatch.writeTextFile({
                filename: geosetterparam,
                data: response.files[f].fileName + '\r\n',
                append: true
                });
            };
            executeGeoSetter();
        });
       
        function executeGeoSetter() {
            IMatch.shellExecute({
                'executable' : '\"' + geosetter + '\"',
                'verb' : 'open',
                'parameters' : ' /PARAMS=\"' + geosetterparam + '\"',
                'showwindow' : true
            });
        };

          // Wait 2000ms
          setTimeout(function() {
              IMatch.modalClose();
              // executeGeoSetter();
          },2000);

    });
</script>


Mario

IMatch.writeTextFile is an asynchronous function which returns a promise.

You wait for it in the same way you wait for the MWS.get(...) call.

IMatch.writeTextFile(...).then(function(response) {
  // File has been written, do stuff.
});
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

axel.hennig


dcb

Thanks for this Axel. One less script I need to convert.

Good pointer as well to the asynchronous info. I didn't know that was occurring but surely explains the file move errors I'm getting when attempting to move from 4 x Dropbox folders to a single import folder.

Code, learn, code again.
Have you backed up your photos today?

sinus

Best wishes from Switzerland! :-)
Markus


ubacher

Thank you. The first App posted which I will use as is!

For others: Be aware of the need to use double \\ in specifying the location of the files,
Here is what I used:

var geosetter = 'C:\\Program Files (x86)\\GeoSetter\\GeoSetter.exe';         
            var geosetterparam = 'C:\\%Temp%\\imatch_geosetter_params.txt';

Mario

QuoteFor others: Be aware of the need to use double \\ in specifying the location of the files,

For all 'C' based languages like C, C++, JavaScript etc. the \ character in strings has a special meaning. For example \r means carriage return, \n means line-feed, \t means tab. To escape the special meaning, you have to use the double \\.

Unfortunately, Windows uses the \ to separate folder name segments. This means that whenever you create a string with a folder name in your code, like:

var fileName = "c:\\data\\images\\food\\egg.jpg"

you need to ensure that you use \\ instead of  \.
Otherwise JavaScript will treat each \ and the following character as a control character. And probably complain when it cannot find a matching control character.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

cytochrome

#10
I have the following problem with this App: when I activate the Geosetter App I see briefly Firefox opening with "Open selected files in GeoSetter" and nothing happens.

The file imatch_geosetter_params.txt shows the selected files like

/COLLECTION
F:\Images\GX7\Décembre-2016\GX7_1003556.RW2
F:\Images\GX7\Décembre-2016\GX7_1003557.RW2
F:\Images\GX7\Décembre-2016\GX7_1003558.RW2
F:\Images\GX7\Décembre-2016\GX7_1003559.RW2

If  then I try to open a file directly in GeoSetter from the File Window I get this warning from GeoSetter:


PS Seems it is not related to the App because when I try to open the files directly from the Windows Explorer I get the same warning! Must be something in my Geosetter settings. The *RW2 file type is defined in the Preferences so I am at a loss. When I open the files directly from within GeoSetter everything is fine

axel.hennig

#11
Quote from: cytochrome on June 05, 2017, 09:31:23 AM
PS Seems it is not related to the App because when I try to open the files directly from the Windows Explorer I get the same warning! Must be something in my Geosetter settings. The *RW2 file type is defined in the Preferences so I am at a loss. When I open the files directly from within GeoSetter everything is fine

Hi cytochrome,

the /COLLECTION mode of GeoSetter was fixed (I think) in version 3.3.57. Do you have this version or a later one?

Try to open the imatch_geosetter_params.txt file (and GeoSetter of course) from command line (or use a batch file). The code should look something like this:


"C:\Program files\or another path\GeoSetter.exe" /PARAMS="D:\path to somewhere\imatch_geosetter_params.txt"


Is this working?

An other thing is the "special character" in your filename (é in Décembre). Try the app in IMatch with files without "special characters". Is it working?

Hope this helps.

axel.hennig

#12
Thanks to everybody in this thread who "liked" this app.

Perhaps someone is able to make a "nicer" icon (geosetter.png file). I'm not really good in these things. First I exported (using IcoFX) the icon from the GeoSetter.exe file, but the resolution wasn't high enough.

cytochrome

#13
Hello Axel,

Thanks for the help.
When I use the following command line "G:\Program Files (x86)\GeoSetter\GeoSetter.exe" /PARAMS="G:\\IMatch6_Util\\imatch_geosetter_params.txt" Geosetter.exe    GeoSetter opens with the same error message as above, but if I clear the message the selected files appear in GeoSetter.

If I select other files in IM6 with GeoSetter still open, click on the App, again nothing but the command line then works: the selected files appear open in GeoSetter without the warning message.

The accented character is no problem with the command line.

So the paramer file is filled correctly, when it is called from a cammand line with GeoSetter closed it opens with a warning but works, with GeoSetter already open it works as expected. From within IM6 it does not work.

I have GeoSetter 3.4.16. In the Help I found  is no reference to Collection mode, but once the Warning is cleared (but not before!) the mention "Collection Mode activated" is displayed over the selected files vignettes. In the Warning "Collection" is not mentioned among the starting modes... Is my GeoSetter version bizarre?


Francis

PS There is no line 31 to modify in v1.1







axel.hennig


axel.hennig

Quote from: cytochrome on June 05, 2017, 04:23:13 PM
When I use the following command line "G:\Program Files (x86)\GeoSetter\GeoSetter.exe" /PARAMS="G:\\IMatch6_Util\\imatch_geosetter_params.txt" Geosetter.exe    GeoSetter opens with the same error message as above, but if I clear the message the selected files appear in GeoSetter.

Sorry, but it is not really clear where your command line ends. Does your command line look like

"G:\Program Files (x86)\GeoSetter\GeoSetter.exe" /PARAMS="G:\\IMatch6_Util\\imatch_geosetter_params.txt" Geosetter.exe


or does it look like

"G:\Program Files (x86)\GeoSetter\GeoSetter.exe" /PARAMS="G:\\IMatch6_Util\\imatch_geosetter_params.txt"


Neither the first nor the second one is correct. Correct would be:

"G:\Program Files (x86)\GeoSetter\GeoSetter.exe" /PARAMS="G:\IMatch6_Util\imatch_geosetter_params.txt"


\ instead of \\

Quote from: cytochrome on June 05, 2017, 04:23:13 PM
I have GeoSetter 3.4.16. In the Help I found  is no reference to Collection mode
I just checked with GeoSetter 3.4.16 and on my system everything is fine (using files with German umlauts in the filename). And you are correct, there is no "/COLLECTION" mode described in the help file. For the old IMatch (IMatch before IMatch 2017) the author of GeoSetter wrote the (Basic-) script "Open selected files in GeoSetter". That's why I know that there is a "collection-mode".

Since there is a warning message when you just use the batch file this can't be IMatch related. Perhaps you should post your behaviour in the GeoSetter Bug Tracker?

Sorry, but I don't know how to help you further.

cytochrome

Hi Axel,

Thank you for the time and pain!

I used the first command line, I added the "geosetter.exe" because you insisted that geosetter had to be open. SIlly, non?

When I use the correct command Geosetter opens without warning and with the selected files. Everything is normal. I had checked that the diacritic characters were not the problem.

But still the App does not work in Imatch. When I select some files and click the App I see briefly Firefox opening with "Open selected files in GeoSetter" then close immediately and nothing happens! If I activate the command line the selected files are displayed in GeoSetter.

So it is not Geosetter but something in IM or the App, probably a setting in IM that is interfering but I can't figure out which one.

OK, let it be, anyway I ingest my photos and assign GPS with Photomechanic, but Geosetter is such a good program, and it is free!

Francis

Mario

#17
I tried out the app and it works here right out of the box (after changing the absolute path to geosetter.exe to match my system).

I noticed that when you launch it too quickly after closing Geosetter, GeoSetter does not start. Maybe it is still shutting down in the background. Waiting a few seconds does the trick.

I modified Axels original script, as a learning experience (me learning from you, that is):

1. I changed the code to use a smaller modal.
This led me to a bug in the AppWizard. It created string-type width/height entries for modals, instead of numeric types. Fixed for the next release.

2. I changed the script to keep the modal open until GeoSetter is starting. This way the user knows what is going on.

3. I changed the hard-coded file name for the parameter file to a dynamic approach.
Using the IMatch.specialFolders function I retrieve the path of the TEMP folder on the system and use that for the parameter file.

4. I changed the logic a bit.
Instead of calling writeTextFile two times, I manage the file contents in a string. When the file contents are complete, I call writeTestFile once.

5. I've created an icon based on what GeoSetter shows in the About dialog.



My version of the script is attached.
@Axel: Feel free to use the icon and other parts you like.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

axel.hennig

Quote from: Mario on June 06, 2017, 11:26:05 AM
@Axel: Feel free to use the icon and other parts you like.

Thanks Mario.

I don't know why I haven't noticed that everything is possible with just one writeTextFile instead of two (GERMAN: Den Wald vor lauter Bäumen nicht sehen...).

sinus

Quote from: axel.hennig on June 06, 2017, 12:18:51 PM
Quote from: Mario on June 06, 2017, 11:26:05 AM
@Axel: Feel free to use the icon and other parts you like.

Thanks Mario.

I don't know why I haven't noticed that everything is possible with just one writeTextFile instead of two (GERMAN: Den Wald vor lauter Bäumen nicht sehen...).

So you improves your knowledge more and more, cool.
Best wishes from Switzerland! :-)
Markus

Mario

Quote from: axel.hennig on June 06, 2017, 12:18:51 PM
Thanks Mario.

I don't know why I haven't noticed that everything is possible with just one writeTextFile instead of two (GERMAN: Den Wald vor lauter Bäumen nicht sehen...).

It should be possible to run the script without an absolute path to geosetter.exe (just use geosetter.exe) if the executable is in the %PATH%.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

cytochrome

#21
Sorry for the mess, since the command line worked I concluded that I had messed something in Index.html. So I downloaded it fresh and modified again and now it works perfectly!!

I think that after sending my intial message I replaced one of the // by / in the geosetter path so it could never find the program.

Thanks to Axel for being patient

Francis

PS And of course it works in Mario's version also now that I learned to take care of synthax

Mario

I suggest to install the ESLint plug-in when you are using Visual Studio Code. It does code-analysis while you type and can highlight syntax errors and stuff. Very useful. Free.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

dcb

Axel, thanks for this script. Would you please try running it from the Timeline window to see what happens. When I do I don't get a file selection. I think the problem is because you use idlist: IMatch.idlist.fileWindowSelection but I'm in the timeline window and so no files are selected. I can't find an equivalent.

When I select the Media & Folders window it works.

Using 2017.6.2
Have you backed up your photos today?

Mario

The fileWindowSelection idlist returns all files currently selected in the file window. If no files are selected, it is empty and the files array returned by the /files endpoint is empty.
The script should handle this by displaying a message to the user or similar.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

dcb

Quote from: Mario on June 10, 2017, 12:09:11 PM
The fileWindowSelection idlist returns all files currently selected in the file window. If no files are selected, it is empty and the files array returned by the /files endpoint is empty.
The script should handle this by displaying a message to the user or similar.

Sound advice.

Is it then the expected behaviour that if I have thumbnails selected in the timeline window, the fileWindowSelection idlist returns nothing? That's what it seems to be doing. It's getting late here so I can do some more testing if needed tomorrow.
Have you backed up your photos today?

Mario

There is no difference between the file window in the Timeline View or any other the other views.
I just checked and iit works perfectly.

You can check yourself: Load the "Sample App: File Window" into an App Panel and then select some files in the file window in the Timeline View.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

axel.hennig

Hello dcb,

I also checked the behaviour in the timeline window. Works perfectly without problems.

dcb

Mario and Axel, I've been able to re-test this morning.

Confirmed, the list of files is showing without problems.

What I am seeing at my end is GeoSetter only launching on every second attempt. Apart from setting the paths, I'm using Axel's script.

1. Select files
2. Run script, launches
3. Select different files,
4. Run script, nothing (filenames are displayed)
5. Run script, launches

I'll keep hunting at this end.
Have you backed up your photos today?

Ger


QuoteMy version of the script is attached.

When trying to unzip the geosetter-new.zip, I get errors on two of the four files. Can somebody add the file again?

Thanks!

PaulS

Here is the version I have from 6/6/2017.  It unzips properly on my computer.

Ger


Mees Dekker

Since a couple of new versions of IMatch, he Geosetter app still appears in the app panel, but does not open any longer. Anybody any clue?

axel.hennig

Hi Mees,

I just checked with IMatch 2020_7_4 with a *.jpg and a *.mp4 file and both worked perfectly.

Axel

Mees Dekker

I do have Geosetter on my computer and it works OK when started from my desktop.

When I select a file and then klik on the Geosetter App (in the app panel), for a very short period (far too short to see what it says) a message comes up. And after that: nothing happens.

Also: when I try to translate the app, I also get a error, saying that resource file has a wrng syntax or is inaccessible.
{ "error": { "code": 1401, "message": "Error reading file. File does not exist or is inaccessible." } }

Any guidance on how to resolve this?

Mario

What do you do in GeoSetter that cannot be done in the IMatch Map Panel?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mees Dekker

Actually I never bothered too much to find out everything about/in the Map Panel. I was used to geosetter and kept using that, since it was very easy to access it form Imatch. But somehow that link is broken on my computer.

Mario

I cannot help with the custom app, but many find that the GPX track import in IMatch works really well. If this is what you do in GS.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

thrinn

Quote from: Mees Dekker on July 24, 2020, 04:33:30 PM
Actually I never bothered too much to find out everything about/in the Map Panel. I was used to geosetter and kept using that, since it was very easy to access it form Imatch. But somehow that link is broken on my computer.
I just downloaded the last version attached to this thread. After changing the path to Geosetter (which is hard-coded in line 26 of index.html), the app works for me.
Best advice I can give if you really need this app: use the Chrome debugger tools to set break points in the then parts of index.html to find out where it fails.
Or you create a Favorite of type External Tool. This should also work, does'nt it?
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mees Dekker

Great: you've made my day.

It works for me now as well (like before). Thanks a lot.