pync.notify not working in python scripts used by launchd
tddschn opened this issue · 1 comments
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 python@3.8 && 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:
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.
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.