Skip to content

Instantly share code, notes, and snippets.

@gatesphere
Last active December 12, 2015 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatesphere/4692706 to your computer and use it in GitHub Desktop.
Save gatesphere/4692706 to your computer and use it in GitHub Desktop.
create-leo.bat
@echo off
:: A batch file which generates other batch files to run the Leo Editor,
:: adapted for the local machine. Optionally, it will also set the Windows
:: filetype and association so .leo files can be opened from Explorer.
::
:: It needs to live in the same folder as "launchLeo.py"
::
:: Open Source X/MIT License
:: initial version * 2012-Dec-13 * matt wilkie <maphew@gmail.com>
:: modified version * 2013-Jan-31 * jacob peck <suschord@suspended-chord.info>
:: revised 2013-May-05 * jacob peck <suschord@suspended-chord.info>
if "%1"=="" goto :Usage
call :pyCheck %1
call :main %1
if "%2"=="register" call :register %1
goto :eof
:main
:: %1 is the path to folder containing python .exe's
set pyexe=%~dp1python.exe
set pywexe=%~dp1pythonw.exe
echo.
echo. Generating...
echo.
echo. Leo.bat - run leo in Windows mode
echo. Leoc.bat - run leo and keep console window open
echo.
echo. These can be placed anywhere in PATH.
echo.
:: leoc.bat - simple
echo @"%pyexe%" "%~dp0launchLeo.py" "%%*" > leoc.bat
:: leo.bat - more complicated
echo @echo off > leo.bat
echo start "leo" /B "%pywexe%" "%~dp0launchLeo.py" "%%*" >> leo.bat
goto :eof
:register
:: perms check courtesy of http://stackoverflow.com/questions/4051883
:: batch-script-how-to-check-for-admin-rights
net session >nul 2>&1
if %errorlevel% == 0 (
echo.
echo. Setting .leo filetype and registering association with Windows
echo.
ftype LeoFile=%pywexe% "%~dp0launchLeo.py" "%%1"
assoc .leo=LeoFile
) else (
echo. Error: Can't set filetype and register association.
echo. Please run from elevated shell to do that.
echo.
)
goto :eof
:pyCheck
if not exist "%1" goto :Usage
goto :eof
:usage
echo.
echo. -=[%~nx0]=-
echo.
echo. Create batch files to launch Leo Editor that can be
echo. placed and run from anywhere on this machine.
echo.
echo. and optionally register filetype with windows
echo.
echo. Usage:
echo. %~n0 "c:\path\to\python.exe"
echo. %~n0 "c:\path\to\python.exe" register
echo.
goto :eof
@gatesphere
Copy link
Author

L32: Good question why I did that... no clue, really. It works, though, for my purposes. %%* is probably correct, and I will revise this.

L34-35: Google says otherwise: http://www.instructables.com/id/Slightly-More-Advanced-Basic-Batch/step2/ECHO-OFFON-Command/
That being said, I did test this both with and without the @echo off line... and it only worked with the @echo off line. At least on my systems (2 win xp, 1 win 7 64).

L21: It was complaining on my WinXP boxes, but that could be a security setting. Both of my WinXP boxes are the property of my employer, and they have some pretty crazy security protocols in place. Not sure if that has anything to do with it, but my WinXP boxes didn't like the extra slash at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment