Как я могу добавить программу в Автозагрузку приложений с помощью скрипта Python? [дубликат]

Я хочу добавить сценарий python для запуска, используя другой сценарий python. Есть ли способ сделать это?

0
задан 17 November 2017 в 22:28

1 ответ

Acc. согласно этой спецификации , размещение файла .desktop в ~/.config/autostart должно работать. Таким образом, в основном задача вашего скрипта Python заключается в

  1. Поместить скрипт Python куда-нибудь
  2. Поместить файл .desktop в ~/.config/autostart.

Вот пример такого сценария

import os

autostart_path      = os.path.expanduser('~/.config/autostart/')
nameofmyscript      = 'myscript.py'
nameofmydesktopfile = 'myscript.desktop'

mypythonscript      = """#!/usr/bin/python
print("hello")"""
desktopfile         = """[Desktop Entry]
Type=Application

# The version of the desktop entry specification to which this file complies
Version=1.0

# The name of the application
Name=Script

# A comment which can/will be used as a tooltip
Comment=My cool python script

# The path to the folder in which the executable is run
Path=%s

# The executable of the application, possibly with arguments.
Exec=%s

# Describes the categories in which this entry should be shown
Categories=Education;Languages;Python;

""" % (autostart_path, nameofmyscript)

# write the desktop file
with open(autostart_path + nameofmydesktopfile, 'w+') as script:
    script.write(desktopfile)

# write the python script; you can place it anywhere actually, just be sure to correct the desktop
# file accordingly
with open(autostart_path + nameofmyscript, 'w+') as script:
    script.write(mypythonscript)

os.system('chmod +x ' + autostart_path + nameofmyscript)
1
ответ дан 17 November 2017 в 22:28

Другие вопросы по тегам:

Похожие вопросы: