Leo script to set .leo association (Windows)

54 views
Skip to first unread message

Matt Wilkie

unread,
Apr 30, 2013, 4:02:57 AM4/30/13
to leo-e...@googlegroups.com
Here is a Leo script which attempts to tell Windows how to handle .leo files, enabling 2x-click "some-workbook.leo" to start. On win7+ it requires Leo be started with elevated admin privileges.


{{{
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo (http://webpages.charter.net/edreamleo/front.html) -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://www.leo-editor.org/2011/leo" >
<leo_header file_format="2"/>
<vnodes>
<v t="maphew.20130429234409.2286"><vh>assoc leo</vh></v>
</vnodes>
<tnodes>
<t tx="maphew.20130429234409.2286">pyexe = g.sys.executable
tmp = g.os.environ['TEMP']

assoc_cmd = 'assoc .leo=Leo.File'
ftype_cmd = 'ftype Leo.File="{0}" "%1" %*'.format(pyexe)

#g.es(pyexe)
#g.es(tmp)
g.es(assoc_cmd)
g.es(ftype_cmd)

from subprocess import Popen
Popen('start "Shell from Leo" cmd.exe /k %s &amp;&amp; %s' % (assoc_cmd, ftype_cmd),
    cwd=tmp, shell=True)
</t>
</tnodes>
</leo_file>
}}}



On Mon, Apr 29, 2013 at 5:21 AM, Edward K. Ream <edre...@gmail.com> wrote:
On Sun, Apr 28, 2013 at 4:11 AM, <joao.i...@gmail.com> wrote:

I just discovered Leo, installed LeoSetup-4.10-final.exe on Windows 7, 64-bit, had a few issues (not finding python 2.7, no Qt installed) which I managed to solve, so now I can launch it. However, there are no icons anywhere (just a blank rectangle with the corner folded), in the Desktop shortcut, in the Start menu, and in the task bar.

This is a problem with the installer.  You can set the icon by hand, by selecting, say, the Desktop shortcut, right-click it, select properties, then icon, etc.

Edward

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Matt Wilkie

unread,
Apr 30, 2013, 4:06:25 AM4/30/13
to leo-e...@googlegroups.com
whups, sent before ready!

to use select and copy text between braces, {{{  }}}, into a Leo outline, select the new node and press Ctrl-B.

adapted from http://stackoverflow.com/questions/8985925/how-to-control-what-version-of-python-is-run-when-double-clicking-a-file/

-matt

Matt Wilkie

unread,
May 1, 2013, 6:23:35 PM5/1/13
to leo-e...@googlegroups.com
...and here's a version that actually works! (previous one just assigned python, and not leo, to the file type).


{{{
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo (http://webpages.charter.net/edreamleo/front.html) -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://www.leo-editor.org/2011/leo" >
<leo_header file_format="2"/>
<vnodes>
<v t="maphew.20130501121440.1885"><vh>Add Windows handler for .leo files</vh></v>
</vnodes>
<tnodes>
<t tx="maphew.20130501121440.1885">@language python
@tabwidth -4

'''Tell Windows how to handle .leo files, enables double clicking on them to open.

To run: in Leo make this the active node and press [Ctrl-B] (execute-script)

It opens a command shell and uses `assoc` and `ftype` commands to inform Windows
where python.exe and the Leo launch script is. It's the equivalent of:

    assoc .leo=Leo.File
    ftype Leo.File="B:\Python27\pythonw.exe" "B:\apps\leo-editor\launchLeo.py" "%1" %*   
       
Requires elevated User Account Control (UAC) priviliges.
See http://superuser.com/questions/88491/force-cmd-exe-to-run-as-admin/
'''

pyexe = g.sys.executable
leo = g.os_path_finalize_join(g.computeLeoDir(), '../launchLeo.py')

tmp = g.os.environ['TEMP']

assoc_cmd = 'assoc .leo=Leo.File'
ftype_cmd = 'ftype Leo.File="{0}" "{1}" "%1" %*'.format(pyexe, leo)

g.es(leo)
g.es(pyexe)

g.es(tmp)
g.es(assoc_cmd)
g.es(ftype_cmd)

from subprocess import Popen
Popen('start "Shell from Leo" cmd.exe /k "{0} &amp;&amp; {1}" '.format(assoc_cmd, ftype_cmd),

Edward K. Ream

unread,
May 2, 2013, 12:14:57 PM5/2/13
to leo-editor
On Wed, May 1, 2013 at 5:23 PM, Matt Wilkie <map...@gmail.com> wrote:
...and here's a version that actually works! (previous one just assigned python, and not leo, to the file type).

I like the direction we are heading here.  Thanks for this work.  I'll test it later.

EKR
Reply all
Reply to author
Forward
0 new messages