Write script to "Send file to device" in bluetooth - printing

I'm relatively new to scripting and using application such as Automator. I would like to try create a script which detects when new images are added to a folder, prints them twice to a device (HP Sprocket) by using the "send file to device" option in Bluetooth, and then moves that image to another folder once the print has been sent (in queue) or completed.
I have used automator to create the transfer of the file, however I have no idea how to go about doing the printing aspect of this. Should I be using applescripts in automator? or another program?
Just for clarification regarding this, this is where the option sits when doing it manually.
The reason I am doing it this way and not just through a standard print is because the HP Sprocket doesn't work as a printer on any devices other than mobile, however you are able to send a file to the device this way with it still printing.

Here are some bits of help:
To detect when files arrive in a folder, you need to Google "Applescript folder actions".
I did something similar to what you are trying and used a folder in Dropbox which allows me to print from a smartphone by dropping files into Dropbox.... neat!
I used a POGO printer in my case, here is the bash code with embedded Applescript at the end:
################################################################################
# POGOprint
# Send image supplied as parameter to Polaroid POGO printer using Bluetooth
# File Exchange
#
# Mark Setchell
################################################################################
# User editable parameters - get address by clicking Bluetooth icon at top-right
# of the Mac screen and looking for the POGO
# Install ImageMagick using "homebrew", with:
# brew install imagemagick
pogo_address="00-04-48-13-9f-64"
tmp="/tmp/POGO.jpg"
# Get width and height of image using ImageMagick
read w h < <(convert "$1" -format "%w %h" info: )
if [ $w -gt $h ]; then
# Landscape format - wider than tall
convert "$1" -resize 900x600 $tmp
else
# Portrait format - taller than wide
convert "$1" -resize 600x900 $tmp
fi
osascript<<EOF
with timeout of 60 seconds
tell application "Bluetooth File Exchange"
send file "$tmp" as string to device "$pogo_address"
end tell
end timeout
EOF

Related

Images from iOS camera are sent rotated in web application

I am building an application in HTML5 for iPad to upload a picture to a server. When I click an input file element like this:
<input id='fileup' type='file' accept='image/*' name='upf' onchange='abv();'/>
It gives the possibility to either take a picture from the device camera or to upload from existing ones. However, when taking a picture, the resulting image is rotated based on the orientation of the device at the moment the photo is taken. What I want to do is to figure out the orientation of the captured image and try to rotate it on the server-side.
Notice that I do not have access to any iOS tools or frameworks, since this application is totally web-based.
Then, is there any information regarding the orientation of the picture that I can either access on the client or on the server-side, such that I would be able to rotate the images into the proper position? I have heard of EXIF data, but I am unsure on how to access it, and if it would give me the required information.
I am using python on the server-side, but a solution in C/C++ would also be appreciated.
Thanks.
I am using python on the server-side
So you can use jpegtran-cffi Python package that provides the ability to perform EXIF auto-transform:
# jpegtran can transform the image automatically according to the EXIF
# orientation tag
photo = JPEGImage(blob=requests.get("http://example.com/photo.jpg").content)
print photo.exif_orientation # "6" (= 270°)
print photo.width, photo.height # "4320 3240"
corrected = photo.exif_autotransform()
print corrected.exif_orientation # "1" (= "normal")
print corrected.width, corrected.height # "3240 4320"
Note: extracted from the README.
As an alternative there is also a convenient command-line tool called jhead that you can use for the same purpose:
# Remove EXIF orientation
# i.e. rotate the image accordingly and reset the orientation
# flag to 1 (default, i.e. origin = TopLeft)
# WARNING: the image file is overwritten!
# NOTE: it also works with a wildcard: jhead -autorot *.jpg
jhead -autorot myimage.jpg

saving data with TextEdit

I want to use TextEdit to save data. what I have so far
tell application "TextEdit"
open /Users/UserName/Desktop/save.rtf
end tell
This gives me
"Expected “given”, “in”, “of”, expression, “with”, “without”, other parameter name, etc. but found unknown token."
and highlights the . in .rtf I tried removing the .rtf
but when I compile it it turns into
(open) / Users / username / desktop / (save)
This code gives "The variable Users is not defined."
also if possible can I have TextEdit run in the background without opening a window?
Put quotes around the path and use POSIX file to get a file object for the path:
tell application "TextEdit"
open POSIX file "/Users/UserName/Desktop/save.rtf"
end tell
You can modify the text of a document by changing the text property:
tell application "TextEdit"
set text of document 1 to text of document 1 & "aa"
end tell
It removes all styles in rich text documents. It also inserts the text as 12-point Helvetica in plain text documents, regardless of the default font.
Creating a new rtf file:
tell application "TextEdit"
make new document at beginning with properties {text:"aa"}
close document 1 saving in POSIX file "/tmp/a.rtf"
end tell
printf %s\\n aa | textutil -inputencoding UTF-8 -convert rtf -stdin -output a.rtf

I need to create a script that will check a files size, warn user, move files and link to new location

We are trying to keep as little end-user data on our companies thin-clients, so I need to create a script that will run when a file is saved locally. I'm completely new to power shell so I do apologize for the lack of knowledge.
Check file size
if (file size is equal or greater than "x"mb) output a warning "file is larger than allowed, moving file to you cloud drive (usually the K: drive)
I'd imaging I'd use Move-Item -destination "k:\My Documents\"
create a link or shortcut to the new file location.
I'm sure I will need more data at some point. I will take any/all the help I can get.
$Directory = Get-ChildItem "D:\Download" #Directory I care about
$SizeLimit = "200000" #Size limit in bytes
foreach ($File in $Directory) {
if ($File.Length -ge $SizeLimit) {
# Notify the user with a pop-up
# the coding for said popup
# Move the file
Move-Item $File.FullName K:\
mklink.exe K:\$File.Name $File.FullName

How to generate thumbnail for PDF file without downloading it fully?

I have to work with external rest API which allows to browse documents library - list docs, get metadata for individual docs and download documents fully or given range.
Currently we show standard icons for all documents (PDF files on server).
We want to improve and show thumbnails.
Is there a way of extracting thumbnail of cover page from PDF without reading whole file? Something similar to EXIF maybe? Client is running on iOS.
Not sure if I fully understand your environment and your limitations.
However, if you can retrieve a 'given range' of a remote document, then it's easy to just retrieve page 1. (You can only retrieve parts of PDF documents which will successfully render if they are "web optimized" a.k.a. "linearized".)
However, nowadays most PDFs do no longer contain thumbnails which could be retrieved. Adobe software (as well as other PDF viewers) do create the page previews on the fly.
So you must retrieve the first page first.
Then Ghostscript can generate a "thumbnail" from this page. Command for Linux/Unix/MacOSX:
gs \
-o thumb.jpg \
-sDEVICE=jpeg \
-g80x120 \
-dPDFFitPage \
firstpage.pdf
Command for Windows:
gswin32c.exe ^
-o thumb.jpg ^
-sDEVICE=jpeg ^
-g80x120 ^
-dPDFFitPage ^
firstpage.pdf
For this example...
...the thumbnail filetype will be JPEG. You can change this to PNG (-sDEVICE=pngalpha, or =png256 or =png16m).
...the thumbnail size will be 80x120 pixel; change it however you need.

Offending Command error while Printing EPS

I am printing an EPS File generated with following credentials.
%-12345X#PJL JOB
#PJL ENTER LANGUAGE = POSTSCRIPT
%!PS-Adobe-3.0
%%Title: InvoiceDetail_combine
%%Creator: PScript5.dll Version 5.2.2
%%CreationDate: 10/7/2011 4:46:59
%%For: Administrator
%%BoundingBox: (atend)
%%Pages: (atend)
%%Orientation: Portrait
%%PageOrder: Special
%%DocumentNeededResources: (atend)
%%DocumentSuppliedResources: (atend)
%%DocumentData: Clean7Bit
%%TargetDevice: (HP Color LaserJet 4500) (2014.200) 0
%%LanguageLevel: 2
%%EndComments
While doing Selection Printing on Ricoh Afficio 2090 or any other drivers/printers get the following error printed on the sheets
ERROR: undefined
OFFENDING COMMAND: F4S47
Stack:
.
Kindly Review and suggest a turn around for the same as i am already stuck in this hell. I have tried to convert/extract in PS but all in vain. I am using gsview to Print and view these files.
This is the problem:
%%PageOrder: Special
A ps document with "Special" page order can NOT be re-ordered. You cannot do a selection or range with this file because it is broken for this use. You must reprocess the file using Distiller or ghostscript (ps2ps or ps2pdf) in order to print selected or re-ordered pages from the document.
You can avoid this by generating your postscript files with a real Postscript™ driver (one not created by Microsoft).
The GSView Documentation has more about this.
Previously:
This line ...
%%TargetDevice: (HP Color LaserJet 4500) (2014.200) 0
... tells us that the file was generated with HP printers as a target. So this really is not an EPS file. Because it's not Encapsulatable. To generate output on a printer the file has to execute the showpage operator, which is a no-no for EPS files.
So uncheck the EPS box (it's a big fat lie, anyway), and select (install) a Generic Postscript driver. If you need to send it to multiple makes of printer, the file needs to make as few assumptions about the printer as possible.
The first thing is that this is not a valid EPS file, as it has PJL attached at the front. Many PostScript printers will strip this off, but by no means all.
This probably is not the source of the problem.
There is no way to 'review' the problem as you have not supplied the complete PostScript program. Without that there is no way to tell what is actually wrong, the error message tells you that the interpreter encountered 'F4547' while trying to parse a token, and that this has not been defined as a routine.
Most likely the file is corrupt, either damaged in some way, or possibly it is a biinary file and has been transmitted by some process which does has done some kind of conversion (CR/LF is common). The offending command looks like its ASCIIHex encoded, so that may be a red herring.
If you want additional help, you are going to have to make the whole program available somewhere.

Resources