Skip to content

Instantly share code, notes, and snippets.

@uranusjr
Last active August 29, 2015 14:17
Show Gist options
  • Save uranusjr/1333a6cd55a34f534288 to your computer and use it in GitHub Desktop.
Save uranusjr/1333a6cd55a34f534288 to your computer and use it in GitHub Desktop.
Script to create a shortcut for Python development on Windows (7 or later)
' Requirements:
' * Windows 7 or later. (Might work on Vista; XP is definitely out.)
' * Python 3 installation. (Will prompt for installation path.)
' The installation path should be both readable and *writable*.
Set fs = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
home = shell.ExpandEnvironmentStrings("%HOMEPATH%")
defaultName = "Python Command Line"
'name = InputBox("Enter link name: [" & defaultName & "] ")
'If Len(Trim(name)) = 0 Then
' name = defaultName
'End If
name = defaultName
' Collect Python path.
path = InputBox("Enter Python path: ")
' Trim trailing backslash.
If StrComp(Right(path, 1), "\") = 0 Then
path = Left(path, Len(path) - 1)
End If
pathString = Join(Array(path, path & "\Scripts"), ";")
' Create "python3" bat.
batPath = path & "\python3.bat"
Set bat = fs.CreateTextFile(batPath)
bat.Write path & "\python.exe %*"
bat.Close
' Create bat file.
batPath = path & "\env.bat"
Set bat = fs.CreateTextFile(batPath)
bat.Write "set PATH=" & pathString & ";%PATH%" & vbCrLf & "cd /D " & home
bat.Close
' Create shortcut to bat file.
linkPath = home & "\Desktop\" & name & ".lnk"
Set link = shell.CreateShortcut(linkPath)
link.TargetPath = shell.ExpandEnvironmentStrings("%COMSPEC%")
link.Arguments = "/A /Q /K " & batPath
link.Save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment