How to select a file (or any other action that changes something)

Started by Carlo Didier, November 04, 2018, 10:08:31 PM

Previous topic - Next topic

Carlo Didier

I tried this

http://127.0.0.1:50519/v1/files?auth_token=&idlist=%40imatch.selectFiles&id=116754

but it doesn't have any effect and doesn't throw any error either.
I can't find an example or explanation in the doc that explains passing parameters to set/change anything through IMWS ...
All the doc explains is how to use it from javascript, like this

IMatch.selectFiles({
     id '1,2,3',
     focus: 1
});

Mario

This endpoint selects the specified files in the active file window.
What do you want to do otherwise?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Quote from: Mario on November 04, 2018, 10:11:23 PM
This endpoint selects the specified files in the active file window.

That's what it should do, but it doesn't! The selection doesn't change to the specified file.

Mario

I just tried the file window sample app (App Manager) which has a feature to select files in the file window. It works. Can you check this and use the code as an example for your own code?

Are you using an App or are you trying to control the file window from an external script or web browser? This may fail, some functions only work when run from an IMatch app running in an app panel for security reasons and because of focus management and context. Selecting files in a file window is not something external scripts usually do.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

I'm trying to do it from a Powershell script (as you suggested I could use Powershell if I don't want to use javascript) like this:

Invoke-WebRequest -Uri "http://127.0.0.1:50519/v1/files?auth_token=&idlist=%40imatch.selectFiles&id='116754'"


Mario

Why would you do that?
IMatch may not even show a file window when your powershell script runs, or it may have no context.
In general: Endpoints provided by IMWS are independent from IMatch and work from anywhere. Endpoints provided only by IMatch are limited to being used from Apps running in IMatch. Many also work in a web browser, but not all.

The endpoints provided by IMatch are wrapped (and documented by) the IMatchLib JavaScript class.
The IMWS endpoints are documented by IMWS itself and can be easy read by the IMWS Documentation App you run run from the App Manager or open in your browser via http://127.0.0.1:50519/imatch/apps/imws-doc/ (When IMatch is running).

What are you trying to do?
Why do you want to select files in a file window from a PowerShell script?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Quote from: Mario on November 05, 2018, 03:18:15 PM
What are you trying to do?
Why do you want to select files in a file window from a PowerShell script?

I'm just trying to find out how to do things in iMatch from Powershell (because you yourself suggested to me to use Powershell for my scripts if I didn't want to use javascript).
What I need in my scripts is for example getting selected files or files in a collection or category, assign categories, create stacks, etc, etc Lots of things.
But if only a very small subset of methods is available from Powershell (or other external script engines), then it's just useless.
If I could do everything my old basic scripts did with Powershell, then I wouldn't need to burn through another hundred days to battle my way through javascript and apps.

Mario

QuoteBut if only a very small subset of methods is available from Powershell (or other external script engines), then it's just useless.

All functions provided by IMWS are available even when IMatch is not running. IMatch Anywhere is based on that and works beautifully.

Controlling the IMatch user interface from a Powershell script is not a good idea. That's not how this should be used. Use IMWS methods, which allow you to query and modify categories and more. For dealing with things like files currently selected in a file window, I recommend using an app.

Still you can retrieve data for the files selected in a file window from PowerShell easily:

http://127.0.0.1:50519/v1/files?idlist=%40imatch.filewindow.active.selection&fields=id%2Cname&auth_token=

I'm using the v1/files endpoint with the idlist: '@imatch.filewindow.active.selection' to get the id and name of all selected files. Not difficult.

Note that a) @ must be URL encoded to %40, but that's standard and b) this only works against the IMWS running in IMatch. The standalone IMWS has no selected files idlist.

As I said in my other post in your other thread about the same thing, you can see the actual HTTP requests when you use the developer tools in your web browser. And then copy them from there into your PowerShell script.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Ok. I never said I was using iMatchAnywhere. I am not. I only use iMatch and I'm perfectly fine with the fact that any Powershell script will only work when iMatch is running. I can easily deal with that. I just want to use Powershell as replacement for javascript for my scripting (as would be possible as per your suggestion).

As this thread has drifted to the same theme as my other post, you can close this one and only answer on the other one.

Mario

I demonstrated how you can use PowerShell to retrieve data for all files currently selected in an IMatch file window. Wasn't this the question?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

No, the question was:
QuoteHow to select a file (or any other action that changes something)

Mario

That was answered as not necessarily working from code running outside IMatch.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier


Mario

All IMWS endpoints work.

I don't explicitly document this for endpoints supplied by IMatch, because these are supposed to be used from within apps, and via the IMatchLib.js wrapper class. Most work. But changing the file window selection or focus from a PowerShell script is not a recommended operation.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

So, to use all functionalities, I may have to use iMatchAnywhere?

Mario

Quote from: Carlo Didier on November 07, 2018, 08:36:48 AM
So, to use all functionalities, I may have to use iMatchAnywhere?
No.

IMWS: The IMatch WebService that gives you access to IMatch databases and tons of functionality. Fully documented. Works the same in IMatch and IMatch Anywhere and can be utilized from other programming languages.

Endpoints supplied by the IMatch Windows desktop application (and published and documented via the IMatchLib.js wrapper class) are designed to be used from within IMatch apps, not from the outside. These endpoints don't exist in IMWS. Most of these endpoints deal with specific IMatch features and are of no use for server environments or access from other platforms or remote computers.

IMatch Anywhere is based on IMWS and of course does not need any endpoints specific to the IMatch desktop application. IMWS and IMatch Anywhere are independent from IMatch. IMatch is only needed to create and update the database, but that will change over time.

If you find yourself in a situation where you have to access or change what is currently selected in an IMatch file window from a PowerShell script, you should reconsider your development approach. A command line scripting language like PowerShell is not the right tool for the job. Write an app instead, which runs under the control of IMatch and is much better suited for this purpose.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Carlo Didier

Well, as you already know, I have tried apps and they just don't cut it for me. They are unsuited for my scripting needs and have caused me endless frustration (asynchronicity, complications and inconsistencies through case sensitivity, etc, etc).
So, per your own suggestion, I want to use Powershell as an alternative.

Within a few hours, I have come far further to my goal with Powershell as in the hundred or so hours spent trying to get javascript apps to work for my needs.

I will not further discuss my choice, because it's mine and I have excellent reasons for it. And I repeat that it was you who suggested several times that I could use Powershell as an alternative.

The scripts I really need are all non-interactive and purely linear, therefore the old basic engine was perfect and javascript with IMWS just makes everything extremely complicated for me without the slightest hint of an advantage.

I know I may be an exception, but that's the way it is. And the beauty of iMatch has always been it's adaptability and scriptability. It was THE main reason I choose it, because nobody else had (and still has) this, at least not to such an extent and at that price.

Mario

Quotethat I could use Powershell as an alternative.

Yes. Or even a real programming language like Python, C#, Java etc.

It's just that some of the endpoints you are trying to use is not designed to be used from the outside, from a scripting language running in a command shell.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook