Skip to content

Commit

Permalink
Add new post: Script to print formatted text from clipboard to a ther…
Browse files Browse the repository at this point in the history
…mal printer
  • Loading branch information
ibbsbbr committed Jan 23, 2024
1 parent 4fec62d commit f602e4c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions _posts/2024-01-23-thermal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
categories:
- Code
tags:
- linux
- scripts
comment: http://dp-dapper.com/
info: aberto.
date: '2024-01-23'
type: post
layout: post
published: true
slug: thermal
title: 'Script to print from clipboard to a thermal printer'

---

```
if ! command -v xclip &>/dev/null; then
echo "xclip could not be found."
exit 1
fi
clipboard_content="$(xclip -o -selection clipboard)"
escaped_content=$(sed 's/%/%%/g' <<<"$clipboard_content")
converted_text=$(iconv -f UTF-8 -t CP850//TRANSLIT//IGNORE <<<"$escaped_content" 2>/dev/null)
if ! printf '\x1B\x40\x1B\x21\x08\x1B\x61\x01%s\x0A\x0A\x0A\x1B\x69' "$converted_text" | lp -d thermal -o raw; then
echo "Failed to print. Please check the printer and its configuration."
exit 1
fi
```

0 comments on commit f602e4c

Please sign in to comment.