Skip to content

Commit a551094

Browse files
authored
Merge pull request #35 from moheladwy/feat/notification-toggler
feat: add notification toggle and bump version to 1.5.0
2 parents 0ef3354 + 1e55f08 commit a551094

5 files changed

Lines changed: 81 additions & 37 deletions

File tree

OCR4Linux.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ========================================================================================================================
22
# Author:
33
# Mohamed Hussein Al-Adawy
4-
# Version: 1.4.2
4+
# Version: 1.5.0
55
# Description:
66
# OCR4Linux.py is a Python script that handles image preprocessing and text extraction using Tesseract OCR.
77
# The script takes an input image, processes it for optimal OCR accuracy, and extracts text while preserving
@@ -152,7 +152,7 @@ def __init__(self):
152152
self.author = "Mohamed Hussein Al-Adawy"
153153
self.email = "mohamed.h.eladwy@gmail.com"
154154
self.github = "https://github.com/moheladwy/OCR4Linux"
155-
self.version = "1.4.2"
155+
self.version = "1.5.0"
156156
self.description = \
157157
" OCR4Linux.py is a Python script that handles image preprocessing\n" + \
158158
" and text extraction using Tesseract OCR. The script takes an input\n" + \

OCR4Linux.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# ========================================================================================================================
33
# Author: Mohamed Hussein Al-Adawy
4-
# Version: 1.4.2
4+
# Version: 1.5.0
55
# Description:
66
# OCR4Linux is a versatile text extraction tool for Linux systems that:
77
# 1. Takes screenshots of selected areas using:
@@ -44,9 +44,10 @@ LOGS_FILE_NAME="$OCR4Linux_CONFIG/OCR4Linux.log"
4444
SLEEP_DURATION=0.5
4545
REMOVE_SCREENSHOT=false
4646
KEEP_LOGS=false
47+
SHOW_NOTIFICATION=false
4748
LANG_SPECIFIED=false
4849
SPECIFIED_LANGS=""
49-
VERSION="v1.4.2"
50+
VERSION="v1.5.0"
5051

5152
langs=()
5253

@@ -69,11 +70,13 @@ show_help() {
6970
echo " -r Remove screenshot in the screenshot directory"
7071
echo " -d DIRECTORY Set screenshot directory (default: $SCREENSHOT_DIRECTORY)"
7172
echo " -l Keep logs"
73+
echo " -n | --notify Show notification after taking the screenshot"
7274
echo " --lang LANGUAGES Specify OCR languages (e.g., 'all', 'eng', 'eng+ara')"
7375
echo " -v | --version Print the package version, then exist"
7476
echo " -h | --help Show this help message, then exit"
7577
echo "Example:"
7678
echo " OCR4Linux.sh -d $HOME/screenshots -l"
79+
echo " OCR4Linux.sh --notify"
7780
echo " OCR4Linux.sh --lang eng+ara"
7881
echo " OCR4Linux.sh --lang all -l"
7982
echo " OCR4Linux.sh -h"
@@ -100,6 +103,10 @@ while [[ $# -gt 0 ]]; do
100103
KEEP_LOGS=true
101104
shift
102105
;;
106+
-n|--notify)
107+
SHOW_NOTIFICATION=true
108+
shift
109+
;;
103110
--lang)
104111
SPECIFIED_LANGS="$2"
105112
LANG_SPECIFIED=true
@@ -230,7 +237,11 @@ choose_lang() {
230237
takescreenshot_wayland() {
231238
log_message "Taking screenshot using grimblast for Wayland..."
232239
sleep $SLEEP_DURATION
233-
grimblast --notify copysave area "$SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
240+
if [ "$SHOW_NOTIFICATION" = true ]; then
241+
grimblast --notify copysave area "$SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
242+
else
243+
grimblast copysave area "$SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
244+
fi
234245
log_message "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME in wayland session"
235246
}
236247

@@ -239,6 +250,9 @@ takescreenshot_x11() {
239250
log_message "Taking screenshot using scrot for X11..."
240251
sleep $SLEEP_DURATION
241252
scrot -s -Z 0 -o -F "$SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME"
253+
if [ "$SHOW_NOTIFICATION" = true ]; then
254+
notify-send "OCR4Linux" "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME" -i camera-photo
255+
fi
242256
log_message "Screenshot saved to $SCREENSHOT_DIRECTORY/$SCREENSHOT_NAME in x11 session"
243257
}
244258

PKGBUILD

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Maintainer: moheladwy <mohamed.h.eladwy@gmail.com>
22
pkgname=ocr4linux-git
3-
pkgver=1.4.2
3+
pkgver=1.5.0
44
pkgrel=1
55
pkgdesc="OCR CLI Tool for Extracting Text from Screenshots using bash and python for both x11 and wayland."
66
arch=('any')
@@ -9,6 +9,7 @@ license=('MIT')
99
depends=(
1010
'python'
1111
'bash'
12+
'libnotify'
1213
'tesseract'
1314
'gawk'
1415
'tesseract-data-eng'
@@ -31,11 +32,11 @@ sha256sums=('SKIP')
3132

3233
pkgver() {
3334
cd "$srcdir/$pkgname" || exit 1
34-
printf "1.4.2.r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
35+
printf "1.5.0.r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
3536
}
3637

3738
package() {
38-
cd "$srcdir/$pkgname" || exit 1
39+
cd "$srcdir/$pkgname" || exit 1
3940

4041
install -Dm755 OCR4Linux.py "${pkgdir}/usr/bin/OCR4Linux.py"
4142
install -Dm755 OCR4Linux.sh "${pkgdir}/usr/bin/OCR4Linux"

README.md

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OCR4Linux
22

3-
**Version:** 1.4.2
3+
**Version:** 1.5.0
44

55
OCR4Linux is a versatile text extraction tool that allows you to take a screenshot of a selected area, extract text using OCR, and copy it to the clipboard. It supports both Wayland and X11 sessions and offers multiple language support.
66

@@ -73,15 +73,34 @@ I didn't find any easy tool in Linux that does the same thing as the PowerToys a
7373

7474
### Option 1: Install from AUR (Recommended)
7575

76-
The easiest way to install OCR4Linux on Arch Linux or any Arch-based distribution is directly from the AUR:
76+
The easiest way to install OCR4Linux on Arch Linux or any Arch-based distribution is directly from the AUR using any AUR helper (e.g., `yay`, `paru`):
7777

7878
```sh
7979
yay -S ocr4linux-git
8080
```
8181

8282
This will automatically install OCR4Linux and all its required dependencies.
8383

84-
### Option 2: Manual Installation
84+
### Option 2: Build from Source (makepkg)
85+
86+
You can clone the repository and build the package manually using `makepkg`:
87+
88+
1. Clone the repository:
89+
90+
```sh
91+
git clone https://github.com/moheladwy/OCR4Linux.git
92+
cd OCR4Linux
93+
```
94+
95+
2. Build and install the package:
96+
97+
```sh
98+
makepkg -si
99+
```
100+
101+
### Option 3: Manual Installation (setup.sh)
102+
103+
If you prefer a local installation in your home directory or want to use the automated setup script:
85104

86105
1. Clone the repository:
87106

@@ -90,7 +109,7 @@ This will automatically install OCR4Linux and all its required dependencies.
90109
cd OCR4Linux
91110
```
92111

93-
2. Run the setup script to install the required packages and copy the necessary files to the configuration directory:
112+
2. Run the setup script:
94113

95114
```sh
96115
chmod +x setup.sh
@@ -106,17 +125,20 @@ This will automatically install OCR4Linux and all its required dependencies.
106125

107126
## Usage
108127

109-
1. Run the main script to take a screenshot, extract text, and copy it to the clipboard:
128+
1. Run the tool to take a screenshot, extract text, and copy it to the clipboard:
110129

130+
If installed via AUR or `makepkg`:
111131
```sh
112-
chmod +x ~/.config/OCR4Linux/OCR4Linux.sh
113-
~/.config/OCR4Linux/OCR4Linux.sh
132+
OCR4Linux
114133
```
115134

116-
Or if you're in the OCR4Linux directory:
135+
If installed via `setup.sh`:
136+
```sh
137+
~/.config/OCR4Linux/OCR4Linux.sh
138+
```
117139

140+
Or if you're in the source directory:
118141
```sh
119-
chmod +x OCR4Linux.sh
120142
./OCR4Linux.sh
121143
```
122144
@@ -174,6 +196,7 @@ The complete OCR4Linux workflow:
174196
| `-r` | Remove screenshot after processing | `false` |
175197
| `-d DIR` | Set screenshot directory | `$HOME/Pictures/screenshots` |
176198
| `-l` | Keep logs | `false` |
199+
| `-n, --notify` | Show notification after screenshot | `false` |
177200
| `--lang LANGUAGES` | Specify OCR languages (bypasses rofi) | Interactive selection |
178201
| `-v, --version` | Print the package version, then exit | - |
179202
| `-h, --help` | Show help message, then exit | - |
@@ -200,34 +223,36 @@ The complete OCR4Linux workflow:
200223
201224
---
202225
203-
#### Using OCR4Linux.sh
226+
#### Using OCR4Linux
204227
205228
```sh
206229
# Basic usage (shows interactive rofi menu)
207-
./OCR4Linux.sh
230+
OCR4Linux
208231
209232
# Direct language specification (bypasses rofi)
210-
./OCR4Linux.sh --lang eng
211-
./OCR4Linux.sh --lang all
212-
./OCR4Linux.sh --lang eng+ara+fra
233+
OCR4Linux --lang eng
234+
OCR4Linux --lang all
235+
OCR4Linux --lang eng+ara+fra
213236
214237
# Save logs and remove screenshot after processing
215-
./OCR4Linux.sh -l -r
238+
OCR4Linux -l -r
216239
217-
# Custom screenshot directory with logging
218-
./OCR4Linux.sh -d ~/Documents/screenshots -l
240+
# Custom screenshot directory with logging and notification
241+
OCR4Linux -d ~/Documents/screenshots -l -n
219242
220243
# Combine language specification with other options
221-
./OCR4Linux.sh --lang eng -l -r
222-
./OCR4Linux.sh --lang all -d ~/screenshots -l
244+
OCR4Linux --lang eng -l -r
245+
OCR4Linux --lang all -d ~/screenshots -l
223246
224247
# Print version
225-
./OCR4Linux.sh -v
248+
OCR4Linux -v
226249
227250
# Show help
228-
./OCR4Linux.sh -h
251+
OCR4Linux -h
229252
```
230253
254+
**Note:** If you are running the script manually without installation, replace `OCR4Linux` with `./OCR4Linux.sh`.
255+
231256
#### Using OCR4Linux.py
232257
233258
```sh
@@ -269,32 +294,35 @@ python OCR4Linux.py --help
269294
- Use `--lang all` only when document language is unknown
270295
- Command-line specification is faster than interactive selection
271296
272-
- **Keyboard Shortcuts**: You can create a keyboard shortcut to run the script for easy access.
297+
- **Keyboard Shortcuts**: You can create a keyboard shortcut to run the script for easy access.
273298
274299
### Example for `Hyprland` users:
275300
276301
- put the following lines in your `hyprland.conf` file:
277302
278303
```conf
279-
$OCR4Linux = ~/.config/OCR4Linux/OCR4Linux.sh
280-
$OCR4Linux_ENG = ~/.config/OCR4Linux/OCR4Linux.sh --lang eng
304+
# If installed via AUR/makepkg
305+
bind = $mainMod SHIFT, E, exec, OCR4Linux # OCR4Linux with interactive selection
306+
bind = $mainMod SHIFT, T, exec, OCR4Linux --lang eng # OCR4Linux with English only
281307
282-
bind = $mainMod SHIFT, E, exec, $OCR4Linux # OCR4Linux with interactive selection
283-
bind = $mainMod SHIFT, T, exec, $OCR4Linux_ENG # OCR4Linux with English only
308+
# If installed via setup.sh
309+
# bind = $mainMod SHIFT, E, exec, ~/.config/OCR4Linux/OCR4Linux.sh
284310
```
285311
286312
### Example for `dwm` users:
287313
288314
- put the following lines in your `config.h` file:
289315
290316
```c
291-
static const char *ocr4linux[] = { "sh", "-c", "~/.config/OCR4Linux/OCR4Linux.sh", NULL };
292-
static const char *ocr4linux_eng[] = { "sh", "-c", "~/.config/OCR4Linux/OCR4Linux.sh --lang eng", NULL };
317+
/* If installed via AUR/makepkg */
318+
static const char *ocr4linux[] = { "OCR4Linux", NULL };
319+
static const char *ocr4linux_eng[] = { "OCR4Linux", "--lang", "eng", NULL };
293320
294321
{ MODKEY | ShiftMask, XK_e, spawn, {.v = ocr4linux } }, // OCR4Linux interactive
295322
{ MODKEY | ShiftMask, XK_t, spawn, {.v = ocr4linux_eng } }, // OCR4Linux English only
296323
```
297324
325+
298326
- **Language Optimization**: For best results:
299327
- Select only the languages present in your document
300328
- Use fewer languages for better performance

setup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# ========================================================================================================================
33
# Author:
44
# Mohamed Hussein Al-Adawy
5-
# Version: 1.4.2
5+
# Version: 1.5.0
66
# Description:
77
# This setup script installs and configures OCR4Linux and its dependencies.
88
# It handles the installation of:
@@ -33,6 +33,7 @@ sys_requirements=(
3333
tesseract
3434
tesseract-data-eng
3535
tesseract-data-ara
36+
libnotify
3637
python
3738
python-numpy
3839
python-pillow

0 commit comments

Comments
 (0)