Using pyshortcuts from Python

Shortcuts can be created from a Python script with:

from pyshortcuts import make_shortcut
make_shortcut('/home/user/bin/myapp.py', name='MyApp', icon='/home/user/icons/myicon.ico')
make_shortcut(script, name=None, description=None, icon=None, working_dir=None, folder=None, terminal=True, desktop=True, startmenu=True, executable=None, noexe=False)

create a desktop shortcut

Parameters:
  • script (string) – path to script, may include command-line arguments

  • name (string or None) – name to display for shortcut [name of script]

  • description (string or None) – longer description of script [name]

  • icon (string or None) – filename for icon file [python icon]

  • working_dir (string or None) – directory where to run the script in

  • folder (string or None) – name of subfolder of Desktop for shortcut [None] (See Note 1)

  • terminal (bool) – whether to run in a Terminal [True]

  • desktop (bool) – whether to add shortcut to Desktop [True]

  • start_menu (bool) – whether to add shortcut to Start Menu [True, except on macOS]

  • executable (string or None.) – name of executable to use [this Python] (see Note 3)

  • noexe (bool) – whether to use no executable, so that the script is entire command [False]

Notes:

  1. folder will place shortcut in a subfolder of Desktop and/or Start Menu

  2. Start Menu does not exist for Darwin / MacOSX

  3. executable defaults to the Python executable used to make shortcut.

Making a shortcut for single python command

A common request and simple use-case for pyshortcuts is to wrap a single python command. An example of this might look like this:

import sys
from pyshortcuts import make_shortcut

pycmd = "_ -m pip install --upgrade pyshortcuts"

make_shortcut(pycmd, name='Update Pyshortcuts')

Note that using _ or {} as the command name will indicate that the current Python executable should be be used. An example that includes an icon is given in the examples folder.

The above could be done from the command line with:

~> pyshortcut -n "Update Pyshortcuts" "_ -m pip install pyshortcuts"