Saturday, July 4, 2020

#1 2020-04-29 10:21:55 am

FreddieMac
Member
Registered: 2019-11-14
Posts: 38

Script to resize a pdf, jpg, png to create outlook thumbnail

I have tried using a service in automator
that receives pdfs files to scale them and added cut to clipboard step but I can't seem to have it working for me.
I don't know how to access the script itself and my mac simply tells me there's an error.
I'd like to click on a pdf, jpg, png, etc and have it scaled to thumbnail size to insert it in Outlook.

Can someone point me to a good resource?
I am pretty handy with bash, js and applescript.

Thanks

Offline

 

#2 2020-04-29 10:29:52 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Script to resize a pdf, jpg, png to create outlook thumbnail

FreddieMac wrote:

I have tried using a service in automator
that receives pdfs files to scale them and added cut to clipboard step but I can't seem to have it working for me.
I don't know how to access the script itself and my mac simply tells me there's an error.
I'd like to click on a pdf, jpg, png, etc and have it scaled to thumbnail size to insert it in Outlook.

Can someone point me to a good resource?
I am pretty handy with bash, js and applescript.

Thanks




Would be useful to know the content of your failing script.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 29 avril 2020 18:29:37

Offline

 

#3 2020-04-29 06:54:54 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 530

Re: Script to resize a pdf, jpg, png to create outlook thumbnail

FreddieMac wrote:

I'd like to click on a pdf, jpg, png, etc and have it scaled to thumbnail size to insert it in Outlook.



FreddieMac. I do not completely understand what your are requesting, but the script contained below reduces the pixel size of an image file. As written, it reduces the greater of the width or height of the image file to the specified targetImageSize. The sips man page details other resize options. I tested this with JPG, PNG, and PDF image files and it worked as expected.

Applescript:

set targetImageSize to 100

set sourceFile to POSIX path of (choose file)

-- Alternative that works on file selected in the Finder
-- tell application "Finder" to set sourceFile to selection as alias
-- set sourceFile to POSIX path of sourceFile

set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set filePath to text 1 thru text item -2 of sourceFile & "/"
set fileName to text item -1 of sourceFile
set AppleScript's text item delimiters to TID

set targetFile to filePath & "ThumbNail - " & fileName

do shell script "sips --resampleHeightWidthMax " & targetImageSize & " " & quoted form of sourceFile & " --out " & quoted form of targetFile

Last edited by peavine (2020-04-30 07:57:30 am)


2018 Mac mini - macOS Catalina

Offline

 

#4 2020-04-30 10:42:48 am

FreddieMac
Member
Registered: 2019-11-14
Posts: 38

Re: Script to resize a pdf, jpg, png to create outlook thumbnail

peavine wrote:
FreddieMac wrote:

I'd like to click on a pdf, jpg, png, etc and have it scaled to thumbnail size to insert it in Outlook.



FreddieMac. I do not completely understand what your are requesting, but the script contained below reduces the pixel size of an image file. As written, it reduces the greater of the width or height of the image file to the specified targetImageSize. The sips man page details other resize options. I tested this with JPG, PNG, and PDF image files and it worked as expected.

Applescript:

set targetImageSize to 100

set sourceFile to POSIX path of (choose file)

-- Alternative that works on file selected in the Finder
-- tell application "Finder" to set sourceFile to selection as alias
-- set sourceFile to POSIX path of sourceFile

set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set filePath to text 1 thru text item -2 of sourceFile & "/"
set fileName to text item -1 of sourceFile
set AppleScript's text item delimiters to TID

set targetFile to filePath & "ThumbNail - " & fileName

do shell script "sips --resampleHeightWidthMax " & targetImageSize & " " & quoted form of sourceFile & " --out " & quoted form of targetFile



This does work wonderful, except I would like to retain the original files.
My idea is to context-menu mouse-click on the image(pdf, jpg, tiff, etc). Have it create a lowres version. Send it to the clipboard in order to paste into an outlook email as a thumbnail.
I know I can probably patch it up here and there. I just thought someone may have inquired on this already?

Thanks!

Offline

 

#5 2020-04-30 10:47:07 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 530

Re: Script to resize a pdf, jpg, png to create outlook thumbnail

FreddieMac wrote:

This does work wonderful, except I would like to retain the original files.



FreddieMac. In my testing, the script retains the original file and creates a new thumbnail file in the same folder. Under what circumstances is the original file overwritten?

Last edited by peavine (2020-05-01 10:09:28 am)


2018 Mac mini - macOS Catalina

Offline

 

#6 2020-04-30 12:27:06 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: Script to resize a pdf, jpg, png to create outlook thumbnail

Alternative workaround. You can play with clipboard yourself. I don't understand completely what you need, because I uninstalled Outlook from my Mac:

Applescript:


-- set aFile to (the clipboard as «class furl»)
set aFile to (choose file of type "public.image") as «class furl»
set newFile to (choose file name)

tell application "Image Events"
   set anImage to open aFile
   scale anImage to size 100
   save anImage as TIFF in newFile with icon
end tell
-- set the clipboard to anImage

NOTE: full disk access required for the Image Events.app. So, give it.

Last edited by KniazidisR (2020-04-30 12:38:04 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#7 2020-04-30 04:46:36 pm

FreddieMac
Member
Registered: 2019-11-14
Posts: 38

Re: Script to resize a pdf, jpg, png to create outlook thumbnail

Thanks All,

I'll cobble it up best I can.
I'm sure I am doing something wrong.
Thank you for this wonderful forum.
I appreciate the contributions made for us newbies to learn.
I love applescript. smile
I love macscripter! smile

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)