-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate
executable file
·120 lines (103 loc) · 4.5 KB
/
template
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
#!/usr/bin/env bash
# VERSION = 0.0.4
# ╭──────────────────────────────────────────────────────────╮
# │ Variables │
# ╰──────────────────────────────────────────────────────────╯
SLEEP_DURATION=0.04s # [EDIT] Increase this value if the script executes so fast that it's missing what it should click.
# [EDIT] Write the names of the plugins here by replacing "items" below
declare -a OPTIONS=(
"Repeat Last"
"item1"
"item2"
)
MISSING_DEPS=()
DEPENDENCIES=(rofi xdotool yad notify-send xclip)
SCRIPT_DIRECTORY=${BASH_SOURCE[0]%/*}
ROFI_THEME="${SCRIPT_DIRECTORY}/rofi-themes/window.rasi"
CACHE="${XDG_CACHE_HOME:-${HOME}/.cache}/aegisub-xdotool.txt"
LOGFILE="/tmp/aegisub-xdotool.txt"
# ╭──────────────────────────────────────────────────────────╮
# │ Check for dependencies │
# ╰──────────────────────────────────────────────────────────╯
for i in "${DEPENDENCIES[@]}"; do
if ! command -v "${i}" >/dev/null; then
MISSING_DEPS+=("${i}")
fi
done
if [[ "${#MISSING_DEPS}" -gt 0 ]]; then
printf -v missing_deps '%s, ' "${MISSING_DEPS[@]}"
notify-send "${missing_deps%, } not found. Please install all missing dependencies."
exit 1
fi
# ╭──────────────────────────────────────────────────────────╮
# │ Functions │
# ╰──────────────────────────────────────────────────────────╯
# Move mouse to ($1, $2) coordinate and left click
xdo() {
xdotool mousemove --sync "$1" "$2"
sleep "${SLEEP_DURATION}"
xdotool click 1
}
# press a key $1 in the keyboard
key() {
sleep "${SLEEP_DURATION}"
xdotool key "$1"
}
# type $1 in the keyboard
typekeys() {
sleep "${SLEEP_DURATION}"
xdotool type "$1"
}
# File selector. The extention of file is $1
select_file() {
# Create cache file if it doesn't exist
[[ -f "${CACHE}" ]] || echo "${HOME}" >"${CACHE}"
DIR=$(cat "${CACHE}")
[[ ! -d "${DIR}" ]] && DIR="${HOME}"
cd "${DIR}" || exit 1
FILETYPE="$1"
FILE=$(yad --width 800 --height 500 --title "Choose ${FILETYPE} file" --file-filter "*.${FILETYPE}" --file)
if [[ ${FILE##*.} != "${FILETYPE}" ]]; then
notify-send "${FILETYPE} file was not selected."
exit 1
else
NEW_DIR=$(dirname "${FILE}")
echo "${NEW_DIR}" >"${CACHE}"
fi
}
check_script_has_opened() {
sleep "${SLEEP_DURATION}"
window_name=$(xdotool getwindowfocus getwindowname | grep "$1")
[[ -z "${window_name}" ]] && notify-send -t 5000 "Script did not open successfully" && exit 1
}
check_non_gui_script_has_opened() {
if xprop; then
notify-send -t 5000 "Script did not open successfully" && exit 1
fi
}
save_to_log_file() {
if ! grep -q "$1" "${LOGFILE}"; then
echo "$1=$2" >>"${LOGFILE}"
fi
}
# ╭──────────────────────────────────────────────────────────╮
# │ Main │
# ╰──────────────────────────────────────────────────────────╯
PLUGIN_NAME=$(printf '%s\n' "${OPTIONS[@]}" | rofi -dmenu -i -p "Plugins:" -theme "${ROFI_THEME}")
if [[ "${PLUGIN_NAME}" == "Repeat Last" ]]; then
while IFS='=' read -r key value; do
declare "${key}=${value}"
done <"${LOGFILE}"
elif [[ -n "${PLUGIN_NAME}" ]]; then
: >"${LOGFILE}"
save_to_log_file "PLUGIN_NAME" "${PLUGIN_NAME}"
fi
case "${PLUGIN_NAME}" in
"item1")
# [EDIT] Put xdotool commands to execute plugin item1 here
;;
"item2")
# [EDIT] Put xdotool commands to execute plugin item2 here
;;
*) ;;
esac