generated from small-tech/watson
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
take-screenshots
executable file
·474 lines (335 loc) · 17.6 KB
/
take-screenshots
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#!/usr/bin/env bash
########################################################################################
#
# task/screenshots
#
# Take localised screenshots of the app for the elementary OS AppCenter.
#
# Copyright ⓒ 2021-present Aral Balkan, Small Technology Foundation.
# Released under GNU GPL version 3.0.
#
########################################################################################
# Configuration.
# Map of languges to keyboard maps (used by setxkbmap to set the keyboard map
# before xdotool types in a localised string).
declare -A languages_to_keyboard_layouts=( ["en"]="us(mac)" ["tr"]="tr(alt)" ["nl"]="nl" )
# Map of languages to full language codes (without the full codes, the correct dictionary
# is loaded for some languages. For example, when launched with LANGUAGE=tr git commit -a, the
# Turkish dictionary is not picked up. However, when launched with LANGUAGE=tr_TR.utf8 commit -a,
# it is. To check what you should map the language code to here, look in /usr/share/hunspell/ and
# map it to the exact name of the file that exists for the language.
declare -A languages_to_full_language_codes=( ["en"]="en" ["tr"]="tr_TR.utf8" ["nl"]="nl" )
# This is the number of times we should press Ctrl+right-arrow to get to the position
# we want the emoji picker to display for the emoji screenshot in a given language.
declare -A emoji_picker_location_for_language=( ["en"]="3" ["tr"]="5" ["nl"]="4" )
# This is the number of times we should press Ctrl+right-arrow to get to the position
# where the localised misspelled word “mistake” is in the given language.
declare -A location_of_spelling_mistake=( ["en"]="3" ["tr"]="2" ["nl"]="2" )
# This is the location of the correct spelling in the list of spelling suggestions
# that we have to arrow-down to get to for each localisation.
declare -A location_of_correct_spelling=( ["en"]="1" ["tr"]="1" ["nl"]="0" )
temporary_git_repository="/tmp/org.small-tech.comet-screenshots"
#
# Setup.
#
echo -e "\n• Building and installing app (will require sudo password)."
# Make sure we have a current build of Comet and that the transations
# are installed.
task/install
echo -e "• Backing up current Git commit message editor."
initial_git_commit_message_editor=$(git config --global core.editor)
echo -e "• Backing up text scaling factor."
# Back up the current text scaling factor so we can restore it at the end.
initial_text_scaling_factor=$(gsettings get org.gnome.desktop.interface text-scaling-factor)
echo -e "• Backing up wallpaper and wallpaper options."
# We’re going to replace the wallpaper with our green screen to chroma key
# the spell check screenshot which requires a screenshot of the screen as
# X11 cannot screenshot context menus in app screenshots so we store the
# existing values here so we can restore them when we’re done.
initial_wallpaper_options=$(gsettings get org.gnome.desktop.background picture-options)
initial_wallpaper_uri=$(gsettings get org.gnome.desktop.background picture-uri)
# Log them just in case we crash so the person doesn’t have to go
# hunting for their wallpaper image.
echo -e " • Wallpaper: ${initial_wallpaper_uri}"
echo -e " • Wallpaper options: ${initial_wallpaper_options}"
echo -e "• Backing up initial keyboard map."
# Save the current keyboard layout as we will be changing it in the script
# to get xdotool to type in the localised strings properly.
initial_keyboard_map="$(setxkbmap -print | grep xkb_symbols | awk -F"+" '{print $2}')"
echo -e " • Keyboard map: ${initial_keyboard_map}"
# Ensure local dictionaries for all supported locales are installed.
echo -e "• Ensuring local dictionaries for all supported locales are installed."
# English
echo -e " • English"
if [[ ! -f "/usr/share/hunspell/en_GB.dic" ]]; then
sudo apt install hunspell-en-gb
fi
# Turkish
echo -e " • Turkish"
if [[ ! -f "/usr/share/hunspell/tr_TR.dic" ]]; then
sudo apt install hunspell-tr
fi
# Nederlands
echo -e " • Nederlands"
if [[ ! -f "/usr/share/hunspell/nl.dic" ]]; then
sudo apt install hunspell-nl
fi
echo -e "• Creating temporary git repository for use in launching app."
# Initialise a new Git working copy.
rm -rf "${temporary_git_repository}"
mkdir "${temporary_git_repository}"
pushd "${temporary_git_repository}"
git init
echo 'small-web.org' > what-is-the-small-web
git add --all
popd
echo -e "• Loading localisation data."
# Get original English string constants from app source.
demonstration_of_line_limit=$(cat src/Constants/AppCenterCopy.vala | sed -rn 's/\s*?public const string DEMONSTRATION_OF_LINE_LIMIT = _\("(.*?)"\);/\1/p')
definition_of_dogma=$(cat src/Constants/AppCenterCopy.vala | sed -rn 's/\s*?public const string DEFINITION_OF_DOGMA = _\("(.*?)"\);/\1/p')
emoji_picker_instructions=$(cat src/Constants/AppCenterCopy.vala | sed -rn 's/\s*?public const string EMOJI_PICKER_INSTRUCTIONS = _\("(.*?)"\);/\1/p')
highlights_spelling_mistakes=$(cat src/Constants/AppCenterCopy.vala | sed -rn 's/\s*?public const string HIGHLIGHTS_SPELLING_MISTAKES = _\("(.*?)"\);/\1/p')
# Get list of localisation languages from app data.
languages=("en")
for language_file_name in $(ls po); do
# Note: the extension test is necessary in addition to the mime-type test
# as .pot files are reported with the same mime-type as .po files and we
# only want to process the latter.
test "${language_file_name: -3}" = ".po" && test "$(file --mime-type -b po/${language_file_name})" = "text/x-po" && {
languages+=("${language_file_name::2}")
}
done;
echo -e "• Setting latest build of Comet (non-Flatpak) as the Git commit message editor."
git config --global core.editor "$(pwd)/build/org.small_tech.comet"
echo -e "• Setting green-screen wallpaper."
# Set the green screen wallpaper.
gsettings set org.gnome.desktop.background picture-options "spanned"
gsettings set org.gnome.desktop.background picture-uri "$(pwd)/task/resources/green-screen.png"
echo -e "• Setting text scaling factor to 1."
# Set the text scaling factor to ensure consistent screenshot size.
gsettings set org.gnome.desktop.interface text-scaling-factor 1
echo -e "• Setting size and position settings for app."
# ~ Center window on 1920x1080 first screen.
gsettings set org.small_tech.comet.saved-state window-position "(206,79)"
gsettings set org.small_tech.comet.saved-state window-size "(540,378)"
echo -e "\n╭────────────────────────────────────────────────────────────────────╮"
echo -e "│ Taking screenshots… PLEASE DO NOT TOUCH THE SYSTEM UNTIL COMPLETE. │"
echo -e "╰────────────────────────────────────────────────────────────────────╯\n"
#
# Take localised screenshots.
#
for language in ${languages[*]}; do
echo -e "\n• ${language}"
echo -e " ==\n"
echo " • Initialising (getting localised strings, keyboard map, etc.) "
# Ensure the directory for the language exists and is empty.
language_directory="../comet-screenshots/${language}"
mkdir -p "${language_directory}"
# Note that while there are newlines (\n) in this string, we do not use gettext’s -e option to expand
# them as we will be re-writing them as carriage returns (\r) so that they display properly
# when written into the Comet windows using xdotool’s type command.
localised_demonstration_of_line_limit="$(LANGUAGE=$language gettext -e org.small_tech.comet "${demonstration_of_line_limit}" | tr '\n' '~' | sed 's/~/\\r/g' | sed 's/\\r$//')"
# localised_demonstration_of_line_limit="${localised_demonstration_of_line_limit}" | tr '\n' '~' | sed 's/~/\\r/g' | sed 's/\\r$//'
echo "${localised_demonstration_of_line_limit}"
localised_definition_of_dogma=$(LANGUAGE=$language gettext org.small_tech.comet "${definition_of_dogma}")
localised_emoji_picker_instructions=$(LANGUAGE=$language gettext org.small_tech.comet "${emoji_picker_instructions}")
localised_highlights_spelling_mistakes=$(LANGUAGE=$language gettext org.small_tech.comet "${highlights_spelling_mistakes}")
# In order for xdotool to type the characters correctly, the correcy keyboard map
# for the language must also be set.
keyboard_map="${languages_to_keyboard_layouts[$language]}"
setxkbmap "${keyboard_map}"
################################################################################
#
# Screenshot 1: Basic Usage (light and dark style montage)
#
# Take screenshots of basic usage demonstrating the line limit warning
# in both light and dark modes and create a montage of the two.
#
################################################################################
echo -e " • Screenshot: Basic usage (light and dark style)\n"
# Set the character limit to 72.
gsettings set org.small_tech.comet.saved-state first-line-character-limit 72
echo -e " › Light style"
echo -e " » Switching system to light colour scheme."
busctl set-property org.freedesktop.Accounts /org/freedesktop/Accounts/User1000 io.elementary.pantheon.AccountsService PrefersColorScheme i 0
echo -e " » Dressing app for screenshot."
pushd "${temporary_git_repository}"
LANGUAGE="${languages_to_full_language_codes[$language]}" git commit &
popd
sleep 1
xdotool search --onlyvisible --class comet windowactivate
xdotoolified_string="$(printf "${localised_demonstration_of_line_limit}")"
# In order for xdotool to type the characters correctly, the correcy keyboard map
# for the language must also be set.
keyboard_map="${languages_to_keyboard_layouts[$language]}"
setxkbmap "${keyboard_map}"
xdotool type --delay=0 "${xdotoolified_string}"
sleep 1
echo -e " » Taking screenshot."
gnome-screenshot --window --include-border --file "${language_directory}/comet-basic-light.png"
sleep 1
echo -e " » Quitting app."
xdotool key Ctrl+q
sleep 1
echo -e " › Dark style"
echo -e " » Switching system to dark colour scheme."
busctl set-property org.freedesktop.Accounts /org/freedesktop/Accounts/User1000 io.elementary.pantheon.AccountsService PrefersColorScheme i 1
echo -e " » Dressing app for screenshot."
pushd "${temporary_git_repository}"
LANGUAGE="${languages_to_full_language_codes[$language]}" git commit &
popd
sleep 1
xdotool search --onlyvisible --class comet windowactivate
xdotoolified_string="$(printf "${localised_demonstration_of_line_limit}")"
xdotool type --delay=0 "${xdotoolified_string}"
sleep 1
echo -e " » Taking screenshot."
gnome-screenshot --window --include-border --file "${language_directory}/comet-basic-dark.png"
sleep 1
echo -e " » Quitting app."
xdotool key Ctrl+q
sleep 1
echo -e " › Creating montage of light and dark style."
# Create montage of light and dark mode using a slanted split-screen effect
# based on the golden mean and maintaining the original soft drop shadow.
magick \
\( "${language_directory}/comet-basic-light.png" +write mpr:comet-basic-light \) \
\( "${language_directory}/comet-basic-dark.png" mpr:comet-basic-light \( -size 1278x952 xc:white -draw "stroke None fill Black path 'M %[fx:w/1.618],0 L %[fx:w-w/1.618],%[fx:h] L %[fx:w],%[fx:h] L %[fx:w],0 Z'" \) -alpha Off -composite +write mpr:montage \) \
\( mpr:montage \( mpr:comet-basic-light -alpha extract \) -compose CopyOpacity -composite +write "${language_directory}/comet-basic-usage.png" \) \
null:
echo -e " › Cleaning up original screenshots."
rm "${language_directory}/comet-basic-light.png"
rm "${language_directory}/comet-basic-dark.png"
echo -e " › Done."
################################################################################
#
# Screenshot 2: Settings Menu
#
################################################################################
echo -e " • Screenshot: Settings\n"
echo -e " › Dressing app for screenshot."
# Set the character limit to 50.
gsettings set org.small_tech.comet.saved-state first-line-character-limit 50
pushd "${temporary_git_repository}"
LANGUAGE="${languages_to_full_language_codes[$language]}" git commit &
popd
sleep 1
xdotool search --onlyvisible --class comet windowactivate
xdotoolified_string="$(printf "${localised_definition_of_dogma}")"
xdotool type --delay=0 "${xdotoolified_string}"
xdotool key Ctrl+comma
sleep 1
xdotool key Tab
sleep 1
echo -e " › Taking screenshot."
gnome-screenshot --window --include-border --file "${language_directory}/comet-settings.png"
sleep 1
echo -e " › Quitting app."
xdotool key Ctrl+q
sleep 1
echo -e " › Done."
################################################################################
#
# Screenshot 3: Emoji support
#
################################################################################
echo -e " • Screenshot: Emoji\n"
echo -e " › Dressing app for screenshot."
# Set the character limit to 72.
gsettings set org.small_tech.comet.saved-state first-line-character-limit 72
pushd "${temporary_git_repository}"
LANGUAGE="${languages_to_full_language_codes[$language]}" git commit &
popd
sleep 1
xdotool search --onlyvisible --class comet windowactivate
xdotoolified_string="$(printf "${localised_emoji_picker_instructions}")"
xdotool type --delay=0 "${xdotoolified_string}"
# Display the emoji picker towards the middle of the window.
xdotool key Home
for ((i = 0; i < "${emoji_picker_location_for_language[$language]}"; i++)); do
xdotool key Ctrl+Right
done
xdotool key Ctrl+period
sleep 1
echo -e " › Taking screenshot."
gnome-screenshot --window --include-border --file "${language_directory}/comet-emoji.png"
sleep 1
echo -e " › Quitting app."
xdotool key Ctrl+q
sleep 1
echo -e " › Done."
################################################################################
#
# Screenshot 4: Spell check
#
################################################################################
echo -e " • Screenshot: Spell check\n"
echo -e " › Dressing app for screenshot."
# Set the character limit to 72.
gsettings set org.small_tech.comet.saved-state first-line-character-limit 72
pushd "${temporary_git_repository}"
LANGUAGE="${languages_to_full_language_codes[$language]}" git commit &
popd
sleep 1
xdotool search --onlyvisible --class comet windowactivate
xdotoolified_string="$(printf "${localised_highlights_spelling_mistakes}")"
xdotool type --delay=0 "${xdotoolified_string}"
xdotool key Home
for ((i = 0; i < "${location_of_spelling_mistake[$language]}"; i++)); do
xdotool key Ctrl+Right
done
xdotool key Menu
sleep 1
xdotool key Right
sleep 1
for ((i = 0; i < "${location_of_correct_spelling[$language]}"; i++)); do
xdotool key Down
done
sleep 1
echo -e " › Taking screenshot."
# Screenshot the window on the green screen background.
# We have to use xdotool as gnome-screenshot does not allow
# you to specify the coordinates via its command-line interface.
spell_check_screenshot_path="${language_directory}/comet-spell-check.png"
gnome-screenshot --file "${spell_check_screenshot_path}"
sleep 1
echo -e " › Quitting app."
xdotool key Escape
xdotool key Ctrl+q
echo -e " › Applying chroma key."
# Crop, trim, and apply a chroma key to the image to extract a screenshot
# with soft shadows.
magick "${spell_check_screenshot_path}" -crop 1600x970+300+70 +repage -trim +write mpr:crop \
\( mpr:crop -channel alpha -fx "1.0*b - 1.0*g + 1.0" -channel RGB -alpha extract +write mpr:mask \) \
\( mpr:crop mpr:mask -alpha Off -fx "v==0 ? 0 : u/v - #00ff00/v + #00ff00" mpr:mask -compose Copy_Opacity -composite +write "${spell_check_screenshot_path}" \) \
null:
echo -e " › Done."
################################################################################
#
# Screenshot 5: Welcome screen
#
################################################################################
echo -e " • Screenshot: Spell check\n"
echo -e " › Launching welcome screen."
# Welcome screen (displays when Comet is launched without any arguments)
LANGUAGE="${languages_to_full_language_codes[$language]}" build/org.small_tech.comet &
sleep 1
xdotool search --onlyvisible --class comet windowactivate
echo -e " › Taking screenshot."
gnome-screenshot --window --include-border --file "${language_directory}/comet-welcome.png"
sleep 1
echo -e " › Quitting app."
xdotool key Ctrl+q
sleep 1
echo -e " › Done."
done;
echo -e "\n• Restoring initial Git commit message editor."
git config --global core.editor "${initial_git_commit_message_editor}"
echo -e "• Restoring initial keyboard map."
# Restore the initial keyboard map.
setxkbmap "${initial_keyboard_map}"
echo -e "• Restoring wallpaper."
# Restore wallpaper.
gsettings set org.gnome.desktop.background picture-options "${initial_wallpaper_options}"
gsettings set org.gnome.desktop.background picture-uri "${initial_wallpaper_uri}"
echo -e "\nDone!\n\nYou can find the screenshots in ../comet-screenshots"