-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 768027b
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# AutoPrinter | ||
|
||
### Português / Portuguese | ||
|
||
Este sistema foi desenvolvido para automatizar o processo de impressão de imagens em uma impressora específica, registrando informações relevantes em um arquivo de log. O sistema possui dois scripts, um em Bash e outro em PowerShell, para sistemas Unix-like e Windows, respectivamente. | ||
Funcionalidades: | ||
|
||
- Automatização da Impressão: | ||
Os scripts aceitam o nome da imagem como parâmetro e verificam se o arquivo existe no diretório especificado. | ||
Caso a extensão da imagem não seja fornecida, o sistema acrescenta automaticamente a extensão '.jpeg' para facilitar o processo. | ||
|
||
- Registro de Logs: | ||
Durante o processo de impressão, os scripts registram as seguintes informações no arquivo de log: | ||
Data e hora de início da impressão. | ||
Informações sobre a imagem e a impressora utilizada. | ||
Data e hora de conclusão da impressão. | ||
|
||
### Uso: | ||
|
||
- Bash (Sistemas Unix-like): | ||
Para utilizar o script em Bash, execute-o no terminal fornecendo o nome do arquivo como argumento. Exemplo: | ||
|
||
```bash | ||
./autoprinter.sh "nome_da_imagem" | ||
``` | ||
|
||
- PowerShell (Windows): | ||
|
||
No PowerShell, execute o script fornecendo o nome do arquivo como argumento. Exemplo: | ||
|
||
```arduino | ||
.\autoprinter.ps1 "nome_da_imagem" | ||
``` | ||
|
||
### Inglês / English | ||
|
||
This system was developed to automate the process of printing images on a specific printer, logging relevant information to a log file. The system consists of two scripts, one in Bash for Unix-like systems and another in PowerShell for Windows. | ||
Features: | ||
|
||
- Automated Printing: | ||
The scripts accept the image name as a parameter and check if the file exists in the specified directory. | ||
If the image extension is not provided, the system automatically appends the '.jpeg' extension for convenience. | ||
|
||
- Logging: | ||
During the printing process, the scripts log the following information to the log file: | ||
Start date and time of the printing process. | ||
Information about the image and the printer used. | ||
Completion date and time of the printing process. | ||
|
||
### Usage: | ||
|
||
- Bash (Unix-like Systems): | ||
To use the Bash script, execute it in the terminal providing the image name as an argument. Example: | ||
|
||
```bash | ||
./autoprinter.sh "image_name" | ||
``` | ||
|
||
- PowerShell (Windows): | ||
|
||
In PowerShell, execute the script providing the image name as an argument. Example: | ||
|
||
```arduino | ||
.\autoprinter.ps1 "image_name" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
param( | ||
[Parameter(Mandatory=$true)] | ||
[string]$fileName | ||
) | ||
|
||
$extension = (Get-Item $fileName).Extension | ||
if ($extension -ne '.jpeg' -and $extension -ne '.jpg') { | ||
$fileName += '.jpeg' | ||
} | ||
|
||
if (-not (Test-Path $fileName)) { | ||
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): The image file '$fileName' was not found." | Out-File -Append -FilePath .\print_log.txt | ||
exit 1 | ||
} | ||
|
||
$printer = Get-Printer | Where-Object { $_.Default } | Select-Object -ExpandProperty Name | ||
|
||
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): Starting printing of file '$fileName' on printer '$printer'" | Out-File -Append -FilePath .\print_log.txt | ||
Start-Process -FilePath 'mspaint' -ArgumentList $fileName -Wait | ||
"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): Printing of file '$fileName' on printer '$printer' completed" | Out-File -Append -FilePath .\print_log.txt | ||
|
||
Write-Host "Image '$fileName' sent for printing to $printer" | ||
Write-Host "Logs saved in print_log.txt" | ||
|
||
# .\autoprinter.ps1 "2468" | ||
# .\autoprinter.ps1 "2468.jpeg" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "$(date '+%Y-%m-%d %H:%M:%S'): Please provide the filename to print." >> print_log.txt | ||
exit 1 | ||
fi | ||
|
||
image_file="$1.jpeg" | ||
|
||
if [ ! -f "$image_file" ]; then | ||
echo "$(date '+%Y-%m-%d %H:%M:%S'): The image file '$image_file' was not found." >> print_log.txt | ||
exit 1 | ||
fi | ||
|
||
printer=$(lpstat -d | awk -F ": " '{print $2}') | ||
|
||
{ | ||
echo "$(date '+%Y-%m-%d %H:%M:%S'): Starting printing of file '$image_file' on printer '$printer'" | ||
lp -d "$printer" "$image_file" | ||
echo "$(date '+%Y-%m-%d %H:%M:%S'): Printing of file '$image_file' on printer '$printer' completed" | ||
} >> print_log.txt | ||
|
||
echo "Image '$image_file' sent for printing to $printer" | ||
echo "Logs saved in print_log.txt" | ||
|
||
#.\autoprinter.sh 2468 |