forked from errorundefined/getspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetspace_osx.py
More file actions
executable file
·140 lines (114 loc) · 4.29 KB
/
getspace_osx.py
File metadata and controls
executable file
·140 lines (114 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
import os
import subprocess
# OSX NOTIFICATION FUNCTION
def notify(title, subtitle, text, kind):
if kind == 'success':
sound = 'Submarine'
else:
sound = 'Basso'
os.system("""
osascript -e 'display notification "{}" with title "{}" subtitle "{}" sound name "{}"'
""".format(text, title, subtitle, sound))
# OSX SCREEN SIZE FUNCTION
def getscreensize():
# import AppKit
# # wrong because in a multi screen setup, it would return the size of the last screen in the array
# for screen in AppKit.NSScreen.screens():
# vw = screen.frame().size.width
# vh = screen.frame().size.height
# return (vw, vh)
# system_profiler SPDisplaysDataType | grep Resolution | grep -oE '[0-9]+' | grep -Eo '[0-9]+$'
systemprofile = subprocess.Popen(["system_profiler", "SPDisplaysDataType"], stdout=subprocess.PIPE)
stdout = systemprofile.communicate()
stdout = stdout[0].splitlines()
for line in stdout:
if "Resolution" in line:
res = [int(s) for s in line.split() if s.isdigit()]
vw = res[0]
vh = res[1]
return (vw, vh)
# OSX FONT DEFINITION VARIABLES
def getfontvars(height, explanation):
from PIL import ImageFont
from math import floor
import textwrap
# 'FUTURA+AVENIR' STYLE
# SET SIZING VARS
fsizehead = int(floor(height / 36))
fsizetext = int(floor(height / 65))
wrapped = textwrap.fill(explanation, 100)
# SET FONT VARS
headfont = ImageFont.truetype("/Library/Fonts/Futura.ttc",fsizehead,index=2)
textfont = ImageFont.truetype("/System/Library/Fonts/Avenir.ttc",fsizetext)
# 'MENLO' STYLE
# SET SIZING VARS
# fsizehead = int(floor(height / 30))
# fsizetext = int(floor(height / 70))
# wrapped = textwrap.fill(explanation, 105)
# SET FONT VARS
# headfont = ImageFont.truetype("/System/Library/Fonts/Menlo.ttc",fsizehead,index=1)
# textfont = ImageFont.truetype("/System/Library/Fonts/Menlo.ttc",fsizetext)
# 'GILL SANS' STYLE
# SET SIZING VARS
# fsizehead = int(floor(height / 35))
# fsizetext = int(floor(height / 55))
# wrapped = textwrap.fill(explanation, 110)
# SET FONT VARS
# headfont = ImageFont.truetype("/Library/Fonts/GillSans.ttc",fsizehead,index=1)
# textfont = ImageFont.truetype("/Library/Fonts/GillSans.ttc",fsizetext,index=7)
# 'HELVETICA NEUE' STYLE
# SET SIZING VARS
# fsizehead = int(floor(height / 30))
# fsizetext = int(floor(height / 57))
# wrapped = textwrap.fill(explanation, 100)
# SET FONT VARS
# headfont = ImageFont.truetype("/System/Library/Fonts/HelveticaNeue.dfont",fsizehead,index=6)
# textfont = ImageFont.truetype("/System/Library/Fonts/HelveticaNeue.dfont",fsizetext,index=1)
# 'SAN FRANCISCO' STYLE
# SET SIZING VARS
# fsizehead = int(floor(height / 35))
# fsizetext = int(floor(height / 65))
# wrapped = textwrap.fill(explanation, 105)
# SET FONT VARS
# headfont = ImageFont.truetype("/System/Library/Fonts/SFCompactText-Heavy.otf",fsizehead)
# textfont = ImageFont.truetype("/System/Library/Fonts/SFCompactText-Light.otf",fsizetext)
return (fsizehead, fsizetext, wrapped, headfont, textfont)
# OSX SET BACKGROUND
def dosetbackground(path):
# GET OSX VERSION NUMBER
import platform
version = platform.mac_ver()
# SET COMMAND DEPENDING ON OSX VERSION
if version[0] >= 10.9:
# AFTER MAVERICKS: SQLITE SOLUTION
# seems to be working though it uses killall Dock and all desktops have to be created from the first
# add an WHERE ROWID='1' ??
setbackgroundcmd = """
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "UPDATE data SET value='{}'" && killall Dock
""".format(path)
else:
# BEFORE MAVERICKS: APPLESCRIPT SOLUTION
setbackgroundcmd = """
osascript -e 'tell application "System Events"
set desktopCount to count of desktops
repeat with desktopNumber from 1 to desktopCount
tell desktop desktopNumber
set picture to "{}"
end tell
end repeat
end tell'
""".format(path)
# setbackgroundcmd = """
# osascript -e 'tell application "System Events" to set picture of every desktop to ("{}" as POSIX file as alias)'
# """.format(path)
os.popen(setbackgroundcmd)
# ADD FUNCTION FOR CHANGING ADMIN LOGIN PNG
# dosetbackground(savein)
# loginimage = '/Library/Caches/com.apple.desktop.admin.png'
# try:
# os.remove(loginimage) # OSX REGENERATES FILE AUTOMATICALLY / or not
# except OSError:
# pass
# admin = img.filter(ImageFilter.GaussianBlur(radius=15))
# admin.save(loginimage)