I have written a small python program (screen.py) that uses the keyboard
lib. The essence of the program is to take screenshots by pressing ctrl + 1 and send them to my github repository by pressing ctrl + 2. Using the keyboard library requires that the program must be launched via sudo.
screen.py:
import keyboard
import pyautogui
import os
screenshot_num = 0
PICS_DIR = os.path.join(os.getcwd(), "pics")
SEND_TO_GIT_SCRIPT = os.path.join(os.getcwd(), "send.sh")
os.makedirs(PICS_DIR, exist_ok=True)
def make_screenshot():
global screenshot_num
myScreenshot = pyautogui.screenshot()
myScreenshot.save(os.path.join(PICS_DIR, str(screenshot_num) + '.png'))
screenshot_num += 1
def send_to_git():
os.system(SEND_TO_GIT_SCRIPT)
keyboard.add_hotkey('Ctrl + 1', make_screenshot)
keyboard.add_hotkey('Ctrl + 2', send_to_git)
keyboard.wait('Alt + q')
The problem is that when the program execution reaches the call to send.sh
(code below), I get the following error:
ERROR:
» sudo python3 screen.py
New Pics
3 files changed, 0 insertions(+), 0 deletions(-)
rewrite screen/pics/0.png (97%)
rewrite screen/pics/1.png (97%)
rewrite screen/pics/2.png (97%)
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
send.sh:
git add ./pics/*
git commit -m 'New Pics'
git push
I connect to github via ssh, the key was created via sudo ssh-keygen. I connect to github via ssh. I have added keys generated both with and without sudo.