From ed91fcab7e02ae66386118482766585a208ed840 Mon Sep 17 00:00:00 2001 From: MagusOscuro <75496058+MagusOscuro@users.noreply.github.com> Date: Sat, 29 Aug 2026 13:59:37 -0400 Subject: [PATCH] Add check function --- autostarter/__init__.py | 2 +- autostarter/autostarter.py | 16 ++++++++++++++++ autostarter/systems/darwin.py | 7 +++++++ autostarter/systems/linux.py | 7 +++++++ autostarter/systems/windows.py | 7 +++++++ setup.py | 2 +- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/autostarter/__init__.py b/autostarter/__init__.py index 3c992bb..4b709e4 100644 --- a/autostarter/__init__.py +++ b/autostarter/__init__.py @@ -1,2 +1,2 @@ -from .autostarter import add, remove +from .autostarter import add, remove, check from .systems import windows, linux, darwin diff --git a/autostarter/autostarter.py b/autostarter/autostarter.py index 640b10e..7dfdc7b 100644 --- a/autostarter/autostarter.py +++ b/autostarter/autostarter.py @@ -10,6 +10,22 @@ def _get_os_module(): """ return importlib.import_module('autostarter.systems.' + platform.system().lower()) +def check(identifier, **kwargs): + """ + Check if the startup script is enabled. + + Parameters: + - identifier (str): The identifier of the startup script to check. + - system_wide (bool, optional): If true, will check for a system wide (all user) startup script. + + Returns: True if the startup script exists and is enabled, False otherwise. + """ + try: + os_module = _get_os_module() + return os_module.check(identifier, **kwargs) + except AttributeError as err: + raise OSError('Operating system is not supported.') from err + def add(script_location, **kwargs): """ Adds a startup script with the specified parameters. diff --git a/autostarter/systems/darwin.py b/autostarter/systems/darwin.py index 694f558..e3253ff 100644 --- a/autostarter/systems/darwin.py +++ b/autostarter/systems/darwin.py @@ -9,6 +9,13 @@ functions for adding and removing launch agents. """ +def check(identifier: str, system_wide: bool = False) -> bool: + """ + Check if the startup script is enabled. + """ + start_file = f'{_startup_folder(system_wide)}/{identifier}.plist' + return os.path.exists(start_file) + def add(identifier: str, script_location: str, interpreter: str = 'sh', system_wide: bool = False, arguments: str = '') -> None: """ diff --git a/autostarter/systems/linux.py b/autostarter/systems/linux.py index 0f44b93..39df05c 100644 --- a/autostarter/systems/linux.py +++ b/autostarter/systems/linux.py @@ -8,6 +8,13 @@ functions for adding and removing startup scripts. """ +def check(identifier: str, system_wide: bool = False) -> bool: + """ + Check if the startup script is enabled. + """ + start_desktop = f'{_startup_folder(system_wide)}/{identifier}.desktop' + return os.path.exists(start_desktop) + def add(identifier: str, script_location: str, interpreter: str = 'sh', system_wide: bool = False, arguments: str = ''): """ diff --git a/autostarter/systems/windows.py b/autostarter/systems/windows.py index e6925dd..67017e0 100644 --- a/autostarter/systems/windows.py +++ b/autostarter/systems/windows.py @@ -8,6 +8,13 @@ functions for adding and removing startup scripts. """ +def check(identifier: str, system_wide: bool = False) -> bool: + """ + Check if the startup script is enabled. + """ + start_file = f'{_startup_folder(system_wide)}\\{identifier}.bat' + return os.path.exists(start_file) + def add(identifier: str, script_location: str, interpreter: str = r'cmd \c', system_wide: bool = False, arguments: str = '') -> None: """ diff --git a/setup.py b/setup.py index 0ba7fb8..e2f9dac 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="autostarter", - version="0.0.1", + version="0.0.2", author="Sam Redmond", author_email="samredmondtech@gmail.com", description="A module for adding and removing startup scripts on Windows, Mac, and Linux systems",