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

pync.notify not working in python scripts used by launchd #47

Open
tddschn opened this issue Sep 25, 2020 · 1 comment
Open

pync.notify not working in python scripts used by launchd #47

tddschn opened this issue Sep 25, 2020 · 1 comment

Comments

@tddschn
Copy link

tddschn commented Sep 25, 2020

Describe the bug
pync.notify doesn't work in python scripts used by launchd, but works when the python script is directly executed.

So I have python script in /Users/tscp/testdir/test-pync/test_pync.py:

#!/usr/local/bin/python3.8
import pync
import sys

print('before')
pync_imported = 'pync' in sys.modules
print(f'pync is imported: {pync_imported}')
pync.notify('test pync')
print('after')

It works as expected (a notification is shown) when run with ./test_pync.py, but doesn't run in my launchd job /Users/tscp/Library/LaunchAgents/test_pync.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>local.job</string>
	<key>Program</key>
	<string>/Users/tscp/testdir/test-pync/test_pync.py</string>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/tmp/local.job.stderr</string>
	<key>StandardOutPath</key>
	<string>/tmp/local.job.stdout</string>
</dict>
</plist>

This is the content of /tmp/local.job.stdout after the job is loaded:

before
pync is imported: True
after

The script seemed to run successfully but the notification was not shown.

To Reproduce
Steps to reproduce the behavior:

brew install [email protected] && python3.8 -m pip install pync

mkdir -p ~/testdir/test-pync
# copy test_pync.py above to ~/testdir/test-pync/test_pync.py
chmod 755 ~/testdir/test-pync/test_pync.py

# copy test_pync.plist above to ~/Library/LaunchAgents/test_pync.plist
# and substitute `/Users/tscp` in the plist file with your home path

launchctl load  ~/Library/LaunchAgents/test_pync.plist
cat /tmp/local.job.stdout

Expected behavior
A notification like this is shown when the job is loaded and run:
image

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Version: tested on both 10.15.6 / 10.15.7.

Additional context
Add any other context about the problem here.

@nihilok
Copy link

nihilok commented Feb 7, 2023

If you install terminal-notifer via homebrew and call directly with os.system for example it works; however the $PATH variable must be set inside the launchd plist file.

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

2 participants