Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autostarter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .autostarter import add, remove
from .autostarter import add, remove, check
from .systems import windows, linux, darwin
16 changes: 16 additions & 0 deletions autostarter/autostarter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions autostarter/systems/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
7 changes: 7 additions & 0 deletions autostarter/systems/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''):
"""
Expand Down
7 changes: 7 additions & 0 deletions autostarter/systems/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down