Windows: register .leo files with OS

43 views
Skip to first unread message

Matt Wilkie

unread,
Feb 28, 2019, 3:06:19 AM2/28/19
to leo-editor
Good news! The Register and Unregister scripts to enable/disable Windows to start Leo from double-clicking on a .leo file now work.  --- For me. testing appreciated. The enhancement issue is https://github.com/leo-editor/leo-editor/issues/1012, but it's probably a good idea to open new issues for bugs so details don't get lost in cross-threads.


They work a) from Leo GUI, b) from Leo command line, and c) from straight python :-) 👍

Python:
python .\leo-editor\leo\scripts\win-register-leo.leox

Leo script:
leo-messages.exe --script=..\scripts\win-register-leo.leox

--Script path must be relative to `leo-editor\leo\core` NOT the filesystem (a bug in Leo core I think).

Leo GUI:

    * Run Leo >> Open specific Leo file >> `scripts.leo` >>  Find "Windows only scripts" node* >> select **`@file win-register-leo.leox`** >> Execute script (Ctrl-B)


* Current node location, subject to change: `.../leo-editor/leo/scripts/scripts.leo#Scripts-->@file leoScripts.txt-->Command-line scripts-->Windows-only scripts`

Expected results

```
(leo-dev) matt@ENV-SURFACE-MHW C:\Users\mattw\code\leo-editor
> python leo\scripts\win-register-leo.leox
--- Running register-leo Leo script
No admin privileges. Start Leo as administrator first and then run this script
--- end of script

```

Open command prompt as Administrator and then retry:

```
matt@ENV-SURFACE-MHW C:\Users\mattw\code
$ c
:\apps\miniconda3\envs\leo-dev\python leo-editor\leo\scripts\win-register-leo.leox
--- Running register-leo Leo script
Attempting to register leo filetype with Windows...
 
Python: c:\apps\miniconda3\envs\leo-dev\pythonw.exe
 
Leo: c:\apps\miniconda3\envs\leo-dev\Scripts\leo.exe
 
Found: c:\users\mattw\code\leo-editor\leo\Icons\LeoDoc.ico
 
Registered!
 
.leo, .leox files associated as 'Leo.File'
--- end of script

matt@ENV
-SURFACE-MHW C:\Users\mattw\code
$ c
:\apps\miniconda3\envs\leo-dev\python leo-editor\leo\scripts\win-unregister-leo.leox
--- Running unregister-leo Leo script
 
Attempting to un-register leo filetype with Windows...
 
Leo file type has been removed from registry
 
.leo, .leox file associations removed from registry
--- end of script

matt@ENV
-SURFACE-MHW C:\Users\mattw\code
$ c
:\apps\miniconda3\envs\leo-dev\Scripts\leo-m.exe --script=..\scripts\win-register-leo.leox

Leo 5.8.1-b2 devel, build 20190222005157, Fri Feb 22 00:51:57 PST 2019
--- Running register-leo Leo script
Attempting to register leo filetype with Windows...
 
Python: c:\apps\miniconda3\envs\leo-dev\pythonw.exe
 
Leo: c:\apps\miniconda3\envs\leo-dev\Scripts\leo.exe
 
Found: c:\users\mattw\code\leo-editor\leo\Icons\LeoDoc.ico
 
Registered!
 
.leo, .leox files associated as 'Leo.File'


```

Remaining to-do before complete: Request elevation prompt when running from Leo gui.



Message has been deleted

Matt Wilkie

unread,
Feb 28, 2019, 3:08:44 AM2/28/19
to leo-editor
Screenshot after registration:

2019-02-28 00_01_36-scripts.png


Edward K. Ream

unread,
Feb 28, 2019, 6:27:04 AM2/28/19
to leo-editor
On Thu, Feb 28, 2019 at 2:06 AM Matt Wilkie <map...@gmail.com> wrote:
Good news! The Register and Unregister scripts to enable/disable Windows to start Leo from double-clicking on a .leo file now work.  --- For me. testing appreciated.

Many thanks for this work.

Edward

Matt Wilkie

unread,
Mar 14, 2019, 5:04:36 AM3/14/19
to leo-editor

With b380d72 there's no longer a need to manually launch Leo or a command shell as administrator. Yay!


register-leo.leox fully working, inc. re-launch elevated

So now both register and unregister work, and we no longer require the
user to manually launch Leo or a CMD shell as administrator. Leo prompts
for elevation at run time.

What's not good: we're using cross-file clones between the scripts
because of the shared request elevation and related code. Have to figure
out how to combine these into a single script, or maybe even move into
Leo itself(?)


The prompt for elevation from just python on the command line does not work. I haven't dug into it because now that we can fire from inside Leo it's less necessary.


To try this out:
  • git checkout out the desktop-links branch
  • Run Leo
    • File >> Open specific leo file >> scripts.leo
    • Navigate to "Scripts-->@file leoScripts.txt-->Windows-only scripts-->@file register-leo.leox"
    • Slap [Ctrl-B] (or use [script-button])
      • You should be asked to confirm relaunch as Administrator
  • Open a folder containing .leo files and verify they sport Leo's icon
  • and/or verify Regedit "Computer\HKEY_CLASSES_ROOT\Leo.File" exists
Repeat with unregister-leo.leox to remove.

--matt


Edward K. Ream

unread,
Mar 14, 2019, 10:52:13 AM3/14/19
to leo-editor
On Thu, Mar 14, 2019 at 4:04 AM Matt Wilkie <map...@gmail.com> wrote:

With b380d72 there's no longer a need to manually launch Leo or a command shell as administrator. Yay!


Well done, you.

Edward
Reply all
Reply to author
Forward
0 new messages