Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to start python script on button click #46

Open
CrazyWolf13 opened this issue Sep 27, 2024 · 0 comments
Open

How to start python script on button click #46

CrazyWolf13 opened this issue Sep 27, 2024 · 0 comments

Comments

@CrazyWolf13
Copy link

Hi

I'd like to create a python script that sends me a windows toast notification and gives me two buttons, one to postpone, and one to start a backup (powershell script).

I tried multiple libraries, like winotify, win10toast, but settled on win11toast.

def on_postpone():
    print("Postponed")

print(f"starting Backup notification")

ps_script = os.path.join(user_folder, 'Pictures', 'Backup_Starter.ps1')
buttons = [
    {'activationType': 'protocol', 'arguments': f'{ps_script}', 'content': 'Start Backup'},
    {'activationType': 'protocol', 'arguments':'', 'content': 'Postpone Backup'}
]
    
# send toast
 toast(
    "Script Ready to Start",
    f"Click 'Start Script' to start, or 'Postpone' to postpone the Backup.",
    duration="long",  
    buttons=buttons,
    audio='ms-winsoundevent:Notification.Looping.Alarm'
)

# if Nothing clicked
print("Postponing the script...")
on_postpone()

While this kinda works, I cannot find a way to make the Start Backup button start the powershell script, it does just open in notepad and also I cannot find a way to execute on_postpone always, except it there was a click on Start Backup.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant