open a note from command line

keldi
Posts: 10
Joined: Fri Sep 27, 2019 9:43 pm
Contact:

open a note from command line

Postby keldi » Mon Nov 01, 2021 11:39 am

Hello,

Is there a way to open a specific note in a specific CintaNotes installation using command line?


Let's say I have several Portable installations of CintaNotes:

Code: Select all

D:\A\CintaNotes.exe
D:\B\CintaNotes.exe
D:\C\CintaNotes.exe
Databases A.db, B.db and C.db are opened, and the notes have links:

Code: Select all

cintanotes://2d49b3d8-8c73-4129-a70e-8c4d7c89d4c7/note/30b0faa3-bece-4e2a-b005-7e024dfcbb06
cintanotes://1071fa4a-dc49-406e-8a82-6a2633213705/note/078958a0-f670-43ad-9957-25188a31b443
cintanotes://5f605449-80bf-4119-8fe3-8526de8e0295/note/f2f18dae-d3a9-46d9-acb9-7dcfe58c156e

I would like to do something like this:

Code: Select all

D:\A\CintaNotes.exe A.db -note 30b0faa3-bece-4e2a-b005-7e024dfcbb06
D:\B\CintaNotes.exe B.db -note 078958a0-f670-43ad-9957-25188a31b443
D:\C\CintaNotes.exe C.db -note f2f18dae-d3a9-46d9-acb9-7dcfe58c156e


So far I found out that I can pass a note link as a parameter (even when Link Protocol isn't registered in the system), but it only works for the last opened instance of CintaNotes.
I mean, if I open portable installations in order A-B-C, this works:

Code: Select all

D:\C\CintaNotes.exe cintanotes://5f605449-80bf-4119-8fe3-8526de8e0295/note/f2f18dae-d3a9-46d9-acb9-7dcfe58c156e
But if I open them in order C-B-A, the command above (for C.db) doesn't work, but the command for A.db does:

Code: Select all

D:\A\CintaNotes.exe cintanotes://2d49b3d8-8c73-4129-a70e-8c4d7c89d4c7/note/30b0faa3-bece-4e2a-b005-7e024dfcbb06
I haven't found a way to make it work for all opened instances, not only the last one.
User avatar
CintaNotes Developer
Site Admin
Posts: 5004
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: open a note from command line

Postby CintaNotes Developer » Tue Nov 09, 2021 2:45 pm

Hi keldi,
thanks for the question and sorry for belated reply!

Can you tell please what exactly "doesn't work" means?

You don't need to tell Cintanotes to open a specific database when you provide a full note link.
The link alone should be enough to switch to the required database, because note link contains notebook uid (the uid between "cintanotes://" and the "/note/" parts).

However! CintaNotes instance needs to be aware of this notebook to be able to open the link.
This means that this notebook should be listed in this instance's File menu before the "Exit" entry. So you need to open this notebook once in this instance.

Hope this helps!
Alex
keldi
Posts: 10
Joined: Fri Sep 27, 2019 9:43 pm
Contact:

Re: open a note from command line

Postby keldi » Thu Nov 18, 2021 9:02 pm

Thank you for your reply.

I copied the folder with Portable Version into 3 different locations. And then I opened in each copy a different database.

Image

I'm trying to open notes from each database in its own already opened CintaNotes installation:

Code: Select all

D:\A\CintaNotes.exe cintanotes://2d49b3d8-8c73-4129-a70e-8c4d7c89d4c7/note/30b0faa3-bece-4e2a-b005-7e024dfcbb06
D:\B\CintaNotes.exe cintanotes://1071fa4a-dc49-406e-8a82-6a2633213705/note/078958a0-f670-43ad-9957-25188a31b443
D:\C\CintaNotes.exe cintanotes://5f605449-80bf-4119-8fe3-8526de8e0295/note/f2f18dae-d3a9-46d9-acb9-7dcfe58c156e

Only one of the three commands from above works at any given moment, depending on whichever CintaNotes.exe was opened last.
My goal is to have three databases opened at the same time (and I want it to be in separate CintaNotes installations, so I can have different hotkeys for them and other settings) and be able to use command line to open a note from any of them.

Before your post I only had one (the opened) database under the File menu in each program. And when I tried the commands above, nothing happened at all (no errors, no notes opened) in two cases out of three.

Now I made sure that each of the programs has all three databases under the File menu. And this time when "D:\C\CintaNotes.exe" was opened last on trying this:

Code: Select all

D:\A\CintaNotes.exe cintanotes://2d49b3d8-8c73-4129-a70e-8c4d7c89d4c7/note/30b0faa3-bece-4e2a-b005-7e024dfcbb06

I'm getting an error:

Code: Select all

---------------------------
[Error]
---------------------------
class app::model::NotebookBusyException
File d:\a\a.db is busy
---------------------------
OK   
---------------------------

After I click on OK:

Code: Select all

---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Assertion failed!

Program: D:\C\CintaNotes.exe
File: .\ui\window.cpp
Line: 465

Expression: false

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application - JIT must be enabled)
---------------------------
Abort   Retry   Ignore   
---------------------------

If I choose Abort, the D:\C\CintaNotes.exe closes.
If I choose Ignore, nothing happens (D:\C\CintaNotes.exe stays open).
If I choose Retry, I get this error:

Code: Select all

---------------------------
CintaNotes
---------------------------
Oops.. something went wrong!
Please press Ctrl+C to copy the error information
and email it to support@cintanotes.com so that we can fix it:

SE EXCEPTION_BREAKPOINT at address 0x00B54EB7 inside D:\C\CintaNotes.exe loaded at base address 0x007C0000

---------------------------
OK   
---------------------------



Regards
User avatar
CintaNotes Developer
Site Admin
Posts: 5004
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: open a note from command line

Postby CintaNotes Developer » Fri Nov 19, 2021 12:25 pm

Ok I see...

Are you sure you actually need 3 separate instances of CN?

I wonder if the following workflow would be ok for you:

- Use 1 instance of CN that has all 3 databases in the File menu;
- Run it as admin and register the cintanotes:// protocol in it (Options/System/Register link protocol)
- When you want to open a link, simply click on it to have the correct DB/note open , or
use the following command line to do it:
start cintanotes://link
e.g. "start cintanotes://2d49b3d8-8c73-4129-a70e-8c ... 024dfcbb06"
Alex
User avatar
CintaNotes Developer
Site Admin
Posts: 5004
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: open a note from command line

Postby CintaNotes Developer » Fri Nov 19, 2021 12:28 pm

Otherwise, please make sure that Options/Startup/Allow multiple instances is set in all 3 copies.
And if you take care yourself of calling the correct instance, have only 1 db file in File menu in each instance - the correct one.

(So that no instance tries to open the db that is currently open in another instance.)
Alex
keldi
Posts: 10
Joined: Fri Sep 27, 2019 9:43 pm
Contact:

Re: open a note from command line

Postby keldi » Fri Nov 19, 2021 2:18 pm

Using one instance isn't a solution for me. I have different font/note list/shortcut settings for each of the databases. And I also often copy notes between them, so having all 3 opened at the same time is important for me.

CintaNotes Developer wrote:Otherwise, please make sure that Options/Startup/Allow multiple instances is set in all 3 copies.
And if you take care yourself of calling the correct instance, have only 1 db file in File menu in each instance - the correct one.

(So that no instance tries to open the db that is currently open in another instance.)
I believe that's the first thing I've tried. Thee CintaNotes.exe with Allow multiple instances, only 1 db under the File menu in each, and then I specified the paths and links in the command line:
path1\CintaNotes.exe cintanotes://link-in-db-1
path2\CintaNotes.exe cintanotes://link-in-db-2
path3\CintaNotes.exe cintanotes://link-in-db-3

What am I doing wrong here? It feels like the last opened instance tries to open all the links despite the specified paths.

Regards
User avatar
CintaNotes Developer
Site Admin
Posts: 5004
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: open a note from command line

Postby CintaNotes Developer » Wed Dec 08, 2021 9:08 am

Hi keldi,

Oh my, sorry for the long silence! I was not aware of your reply. Don't know how this could have happened.
The forum stopped notifying me of new posts for some reason. Please send a reminder to jenter@cintanotes.com
if you need a speedy reply!

Ok, probably this is not relevant to you anymore, but just in case it is:

I replicated your setup, and indeed, there is an issue.
The problem is that when you call cintanotes.exe from the command line, you're not calling that instance directly.
Basically you're running a NEW (4th) instance that just happens to be at the same path.
This newly run instance detects that there's a note link to open and asks the OS if other CN instances are maybe already running (by enumerating the
windows that have CN's window class). And the last run instance always comes first during this enumeration, and always gets the task
to open the notelink (which it is not always able to do).

The fix for this is actually not that difficult: instead of picking up the first window with the corresponding window class, we need to enumerate
all of them, and prefer the one that has the same exe module path as we do.

I could do it if it's still important to you.
Alex
keldi
Posts: 10
Joined: Fri Sep 27, 2019 9:43 pm
Contact:

Re: open a note from command line

Postby keldi » Wed Dec 08, 2021 6:58 pm

CintaNotes Developer wrote:The fix for this is actually not that difficult: instead of picking up the first window with the corresponding window class, we need to enumerate all of them, and prefer the one that has the same exe module path as we do.

I could do it if it's still important to you.
Yes, please! I'd love that.
And thank you for the detailed explanation of inner-workings, It made it all clear why I was unable to make it work.
I guess you'll see my reply when you see it. I don't mind the wait.

Regards
User avatar
CintaNotes Developer
Site Admin
Posts: 5004
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: open a note from command line

Postby CintaNotes Developer » Thu Dec 09, 2021 5:13 pm

Ok, no problem, I'll try to fit this into my schedule this/next week. Will keep you posted here!
Alex
keldi
Posts: 10
Joined: Fri Sep 27, 2019 9:43 pm
Contact:

Re: open a note from command line

Postby keldi » Mon Jan 03, 2022 6:35 am

Happy New Year!
Any news about the fix?
User avatar
CintaNotes Developer
Site Admin
Posts: 5004
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: open a note from command line

Postby CintaNotes Developer » Mon Jan 03, 2022 9:44 am

Hi keldi,

Happy new year to you too!
Sorry it was a really busy week before the new year. The fix will be ready by the end of this week, I promise!
Alex
User avatar
CintaNotes Developer
Site Admin
Posts: 5004
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: open a note from command line

Postby CintaNotes Developer » Sat Jan 08, 2022 12:22 pm

Hi Keldi

Well the fix is ready or so it seems :) thanks for your patience.
Please try it out
http://cintanotes.com/files/beta/CintaN ... _Beta3.zip
Alex
keldi
Posts: 10
Joined: Fri Sep 27, 2019 9:43 pm
Contact:

Re: open a note from command line

Postby keldi » Sun Jan 09, 2022 1:49 pm

Thank you very much! Now it works exactly as I wanted it to: several instances opened at the same time and outside links open in the correct instance. :D
User avatar
CintaNotes Developer
Site Admin
Posts: 5004
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: open a note from command line

Postby CintaNotes Developer » Mon Jan 10, 2022 3:37 am

Cool :D glad I could help!
Alex

Return to “CintaNotes Personal Notes Manager”