### Install PyAutostart Source: https://github.com/eliasdolinsek/pyautostart/blob/main/README.md Install the PyAutostart library using pip. ```bash pip install pyautostart ``` -------------------------------- ### WindowsAutostart Example Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt Example of how to get the path for a batch file and disable an autostart entry on Windows. ```APIDOC # Get the full path to the batch file bat_path = WindowsAutostart.get_path_for_name("com.example.myapplication") print(bat_path) # Output: C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\com.example.myapplication.bat # Disable autostart (removes the batch file) try: autostart.disable(name="com.example.myapplication") except FileNotFoundError: print("Autostart entry does not exist") ``` -------------------------------- ### Custom Autostart Implementation Example Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt An example of a custom autostart handler that extends the abstract base class. This demonstrates how to implement the enable, disable, and is_enabled methods for a specific platform or custom logic. ```python class CustomAutostart(Autostart): def enable(self, name: str, options: dict = None): # Custom implementation print(f"Enabling autostart for {name}") def disable(self, name: str): # Custom implementation print(f"Disabling autostart for {name}") def is_enabled(self, name: str) -> bool: # Custom implementation return False ``` -------------------------------- ### Manage Windows Startup Folder Autostart with WindowsAutostart Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt Use WindowsAutostart to manage autostart entries on Windows by creating batch files in the Startup folder. Enable autostart with either a default 'start ""' command for executables or a custom command for scripts. ```python from pyautostart import WindowsAutostart # Initialize the Windows autostart manager autostart = WindowsAutostart() # Enable autostart with default 'start ""' command # This creates a .bat file that runs the executable options = { "executable": "C:\\path\\to\\your\\application.exe" } autostart.enable(name="com.example.myapplication", options=options) # Creates batch file with content: start "" C:\path\to\your\application.exe # Enable autostart with a custom command # Useful for running scripts or applications with specific launchers options_custom = { "executable": "C:\\path\\to\\script.py", "command": "python" } autostart.enable(name="com.example.pyscript", options=options_custom) # Creates batch file with content: python C:\path\to\script.py # Check if autostart is enabled if autostart.is_enabled("com.example.myapplication"): print("Application will run at startup") ``` -------------------------------- ### Get Windows Autostart Path Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt Retrieves the full path for a Windows autostart batch file given a name. This is useful for locating or verifying the existence of an autostart entry. ```python bat_path = WindowsAutostart.get_path_for_name("com.example.myapplication") print(bat_path) ``` -------------------------------- ### Manage Autostart with SmartAutostart Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt Use SmartAutostart for platform-independent autostart management. Initialize the class and then use enable, is_enabled, and disable methods. The 'args' option specifies the executable path. ```python from pyautostart import SmartAutostart # Initialize the platform-independent autostart manager autostart = SmartAutostart() # Enable autostart for an executable # The 'args' key contains a list of command arguments (typically the executable path) options = { "args": [ "/path/to/your/application" ] } autostart.enable(name="com.example.myapplication", options=options) # Check if autostart is enabled for a specific application if autostart.is_enabled("com.example.myapplication"): print("Autostart is enabled") # Disable autostart when no longer needed autostart.disable(name="com.example.myapplication") ``` -------------------------------- ### Enable Autostart (Platform Independent) Source: https://github.com/eliasdolinsek/pyautostart/blob/main/README.md Enable an executable to run after login using the SmartAutostart class. The 'options' dictionary must include 'args' with the path to the executable. The 'name' parameter determines the created file's name. ```python from pyautostart import SmartAutostart autostart = SmartAutostart() options = { "args": [ "/path/to/executable/file" ] } autostart.enable(name="com.example.myapplication", options=options) ``` -------------------------------- ### Enable Autostart on Windows Source: https://github.com/eliasdolinsek/pyautostart/blob/main/README.md Set up an executable to run after login on Windows using WindowsAutostart. The 'options' dictionary requires an 'executable' key with the path to the file. A .bat file will be created. ```python from pyautostart import WindowsAutostart autostart = WindowsAutostart() options = { "executable": "C:\\path\\to\\your\\executable", } autostart.enable(name="com.example.myapplication", options=options) ``` -------------------------------- ### Enable Autostart on macOS Source: https://github.com/eliasdolinsek/pyautostart/blob/main/README.md Configure an executable to run after login on macOS using MacAutostart. The 'options' dictionary should contain launchd configurations like 'Label', 'RunAtLoad', and 'ProgramArguments'. ```python from pyautostart import MacAutostart autostart = MacAutostart() options = { "Label": "Name of the job", "RunAtLoad": True, "ProgramArguments": [ "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3", "/path/to/your/file.py" ] } autostart.enable(name="com.example.myapplication", options=options) ``` -------------------------------- ### Manage macOS Launchd Autostart with MacAutostart Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt Utilize MacAutostart for direct integration with macOS's launchd system. Initialize with a default or custom base path. Provide launchd-specific options like 'Label' and 'ProgramArguments' when enabling autostart. The is_enabled, get_path_for_name, and disable methods are available for management. ```python from pyautostart import MacAutostart # Initialize with default path (~/Library/LaunchAgents) autostart = MacAutostart() # Or specify a custom base path autostart = MacAutostart(base_path="/custom/path/to/LaunchAgents") # Enable autostart with launchd options # 'Label' identifies the job, 'ProgramArguments' is the command to execute options = { "Label": "My Application Launcher", "RunAtLoad": True, "ProgramArguments": [ "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3", "/path/to/your/script.py", "--some-argument" ] } autostart.enable(name="com.example.myapplication", options=options) # Creates: ~/Library/LaunchAgents/com.example.myapplication.plist # Check if a specific autostart entry exists is_active = autostart.is_enabled("com.example.myapplication") print(f"Autostart enabled: {is_active}") # Output: Autostart enabled: True # Get the full path to the plist file plist_path = autostart.get_path_for_name("com.example.myapplication") print(plist_path) # Output: /Users//Library/LaunchAgents/com.example.myapplication.plist # Disable autostart (removes the plist file) try: autostart.disable(name="com.example.myapplication") except FileNotFoundError as e: print(f"Autostart entry not found: {e}") ``` -------------------------------- ### Autostart Base Class - Abstract Interface Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt The `Autostart` abstract base class defines the interface for all platform-specific autostart implementations. It includes methods for enabling, disabling, and checking the status of autostart entries. ```APIDOC ## Autostart Base Class - Abstract Interface The `Autostart` abstract base class defines the interface that all platform-specific implementations must follow. It provides three core methods: `enable()` for adding autostart entries, `disable()` for removing them, and `is_enabled()` for checking if an autostart entry exists. Custom implementations can extend this class to support additional platforms. ### Methods #### `enable(name: str, options: dict = None)` * **Description**: Add a file to automatic boot. * **Parameters**: * `name` (str) - Required - Desired name for autostart file without file ending. * `options` (dict) - Optional - Platform-dependent information like executable path. #### `disable(name: str)` * **Description**: Remove a file from automatic boot. * **Parameters**: * `name` (str) - Required - Name of autostart file without file ending. #### `is_enabled(name: str) -> bool` * **Description**: Check if an autostart file exists. * **Parameters**: * `name` (str) - Required - Name of autostart file without file ending. * **Returns**: * bool - True if autostart file exists, False otherwise. ### Example: Implementing a custom autostart handler ```python from abc import ABC, abstractmethod class Autostart(ABC): """Abstract base class for autostart implementations.""" @abstractmethod def enable(self, name: str, options: dict = None): """ Add a file to automatic boot. :param name: Desired name for autostart file without file ending :param options: Platform-dependent information like executable path """ pass @abstractmethod def disable(self, name: str): """ Remove a file from automatic boot. :param name: Name of autostart file without file ending """ pass @abstractmethod def is_enabled(self, name: str) -> bool: """ Check if an autostart file exists. :param name: Name of autostart file without file ending :return: True if autostart file exists, False otherwise """ pass # Example: Implementing a custom autostart handler class CustomAutostart(Autostart): def enable(self, name: str, options: dict = None): # Custom implementation print(f"Enabling autostart for {name}") def disable(self, name: str): # Custom implementation print(f"Disabling autostart for {name}") def is_enabled(self, name: str) -> bool: # Custom implementation return False ``` ``` -------------------------------- ### Autostart Abstract Base Class Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt Defines the interface for all platform-specific autostart implementations. Requires custom implementations to provide enable, disable, and is_enabled methods. ```python from abc import ABC, abstractmethod class Autostart(ABC): """Abstract base class for autostart implementations.""" @abstractmethod def enable(self, name: str, options: dict = None): """ Add a file to automatic boot. :param name: Desired name for autostart file without file ending :param options: Platform-dependent information like executable path """ pass @abstractmethod def disable(self, name: str): """ Remove a file from automatic boot. :param name: Name of autostart file without file ending """ pass @abstractmethod def is_enabled(self, name: str) -> bool: """ Check if an autostart file exists. :param name: Name of autostart file without file ending :return: True if autostart file exists, False otherwise """ pass ``` -------------------------------- ### Disable Autostart on Windows Source: https://github.com/eliasdolinsek/pyautostart/blob/main/README.md Remove the autostart configuration on Windows by deleting the created .bat file. The 'name' parameter must match the one used during enabling. ```python from pyautostart import WindowsAutostart autostart = WindowsAutostart() autostart.disable(name="com.example.myapplication") ``` -------------------------------- ### Disable Autostart (Platform Independent) Source: https://github.com/eliasdolinsek/pyautostart/blob/main/README.md Disable automatic execution by deleting the file created by autostart.enable. The 'name' parameter must match the one used during enabling. ```python from pyautostart import SmartAutostart autostart = SmartAutostart() autostart.disable(name="com.example.myapplication") ``` -------------------------------- ### Disable Windows Autostart Entry Source: https://context7.com/eliasdolinsek/pyautostart/llms.txt Disables an autostart entry on Windows by removing the corresponding batch file. Includes error handling for cases where the entry does not exist. ```python try: autostart.disable(name="com.example.myapplication") except FileNotFoundError: print("Autostart entry does not exist") ``` -------------------------------- ### Disable Autostart on macOS Source: https://github.com/eliasdolinsek/pyautostart/blob/main/README.md Disable automatic execution on macOS by removing the launch agent file. The 'name' parameter must match the one used during enabling. ```python from pyautostart import MacAutostart autostart = MacAutostart() autostart.disable(name="com.example.myapplication") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.