Hello, it is delicious. This article is the first of the implementation commentary articles because I don't want to deal with people with dirty desktops. It becomes. If you want to know about the implementation, please see the article!
This time I used yaml and csv for the config file.
It was good to go out so that the user could easily change the settings, but when I tried to make it cli, I was in trouble with the location. After all, I solved it by creating a folder called .myscreenshot under home dir. It may be a little force.
I wrote a configuration file and tried to move it happily, but it didn't work. When I wondered why, the "~" contained in the path was interpreted only as a nyoro.
dirname="~/.myscreenshot"
The solution is as follows
from os.path import expanduser
home=expanduser("~")
dirname=dirname.replace("~",home)
I implemented it by hitting a command using subprocess.
import subprocess
res = subprocess.run(
"defaults read com.apple.screencapture location",
shell=True,
capture_output=True)
if res.returncode == 0:
dirname = res.stdout[:-1].decode()
else:
dirname = "~/Desktop"
res = subprocess.run(
"defaults read com.apple.screencapture name",
shell=True,
capture_output=True)
if res.returncode == 0:
prefix = res.stdout[:-1].decode()
else:
prefix = "screenshot"
Since the return value also includes a line break, it is deleted. Also, since it is a byte type, it is decoded.
This is relatively easy to implement using a library called python-daemon.
The second part is here!
Recommended Posts