I have a script to shrink pictures that stopped working under 10.15.

My fault,
I edited message #45 to repair my error.

OK testing in 10.15. same jpeg as before.

Without cleaning first. 1.8MB > run on 800 > shows briefly 45kb > ends at 2.2GB > icon stays the same.

With cleaning first. 1.8MB > clean > 1.6MB > run on 800 > shows briefly 45kb > ends at 2.2GB > icon has gotten larger.

So runs clearly happily under 10.13 not under 10.15.

NO, NO and NO.

I can’t guess what you really did but I repeat: I’m sure that the script listed in this message didn’t shrink the picture, it does ABSOLUTELY NOTHING".

The main problem here is that you don’t understand what the instructions are supposed to achieve.

I will try to explain them one by one.

on open draggeditems
Is the entry point used when something is dropped upon the app’s icon

--set draggeditems to choose file of type {"public.jpeg"} with multiple selections allowed

Is a disabled instruction which I enable when I test the script in its applet structure (in such case, on open draggeditems is disabled)

--set text1 to my recolle(draggeditems, linefeed) 

When it’s enabled, this instruction change the list of files dragged on the icon into a block of text like :
SSD 1000:Users::desktop:DSC_0257 - opposite.jpg
SSD 1000:Users:
:desktop:DSC_0257 - rotated.jpg
SSD 1000:Users::desktop:DSC_0257 - upDown.jpg
SSD 1000:Users:
:desktop:DSC_0257.JPG

--repeat with aFile in draggeditems
--set contents of aFile to quoted form of POSIX path of aFile & space
--end repeat

When it’s enabled, this loop replace the list of dropped aliases by a list of quoted POSIX paths
like :
{“/Users//Desktop/DSC_0257 - opposite.jpg", "/Users//Desktop/DSC_0257 - rotated.jpg”, “/Users//Desktop/DSC_0257 - upDown.jpg", "/Users//Desktop/DSC_0257.JPG”}

--set text2 to my recolle(draggeditems, linefeed)

When it’s enabled, this instruction change the list of POSIX Paths into a block of text like :
“‘/Users//Desktop/DSC_0257 - opposite.jpg’
'/Users/
/Desktop/DSC_0257 - rotated.jpg’
‘/Users//Desktop/DSC_0257 - upDown.jpg’
'/Users/
/Desktop/DSC_0257.JPG’”

-- display dialog text1 & linefeed & text2

When it’s enabled, this instruction display the block of text built just before.

-- do shell script "sips --resampleHeightWidthMax 50000 " & draggeditems

When it’s enabled, this instruction apply the command supposed to shrink the files described by the list of quoted POSIX Paths.

end open
This instruction is the the end point of the handler.
In the posted script, all these instructions, except on open draggeditems an end open, are disabled so they do nothing.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 15:31:37

Which script are you describing now?

I guess that it’s the one entitled “three sizes.scpt”
May you, at last, post what you are asked to do:
I want to see the log history.

I carefully sent you a copy of it showing in huge 24 points size the different descriptions of the file.

With the original file which you sent to me, you were supposed to see three dialogs,
dialog #1
"origSizeXXX : 1754025 bytes
origDimensions : 3264, 1836
origResolution : 72,0, 72,0
newDimensions : 800, 450
newResolution : 72,0, 72,0
newSize800 : 52949 bytes

dialog #2
"origSize800 : 52949 bytes
origDimensions : 800, 450
origResolution : 72,0, 72,0
newDimensions : 1600, 900
newResolution : 72,0, 72,0
newSize1600 : 126642 bytes

step#3
"origSize1600 : 126642 bytes
origDimensions : 1600, 900
origResolution : 72,0, 72,0
newDimensions : 3200, 1800
newResolution : 72,0, 72,0
newSize3200 : 320141 bytes

I don’t understand how you may have missed that because you were urged three times to click the button [OK] in the dialogs displaying the values listed above.

This said, if you save the script below as an application (a droplet)

on open draggeditems
	tell application "Image Events" to launch
	repeat with currentFile in draggeditems
		tell application "Image Events"
			set openedFile to open file (currentFile as string)
			scale openedFile to size 678 --<<<< here we define the wanted greater dimension
			save openedFile with icon
			close openedFile
		end tell
	end repeat
end open

and drag and drop a jpeg file on its icon, you will get a file whose greater dimension is 678 pixels.

If you save the script below as an application (a droplet)

on open draggeditems
	tell application "Image Events" to launch
	repeat with currentFile in draggeditems
		tell application "Image Events"
			set openedFile to open file (currentFile as string)
			scale openedFile to size 800 --<<<< here we define the wanted greater dimension
			save openedFile with icon
			close openedFile
		end tell
	end repeat
end open

and drag and drop a jpeg file on its icon, you will get a file whose greater dimension is 800 pixels.

If you save the script below as an application (a droplet)

on open draggeditems
	tell application "Image Events" to launch
	repeat with currentFile in draggeditems
		tell application "Image Events"
			set openedFile to open file (currentFile as string)
			scale openedFile to size 1200 --<<<< here we define the wanted greater dimension
			save openedFile with icon
			close openedFile
		end tell
	end repeat
end open

and drag and drop a jpeg file on its icon, you will get a file whose greater dimension is 1200 pixels.

Must I continue ?

As I already wrote, don’t edit one to change the wanted size, apply copy from a script, paste in a blank one, edit the size to fit your needs, save it as an application with a new name.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 16:00:05

I tested all of these script, did not change anything, copied straight from forum in apple script, running under 10.15. no file change is happening - as in getting smaller.

Script one increases the file by 0.4MB
Script two increases the file by 0.4MB
Script three increases the file by 0.9MB

All scripts increase the icon size.

Yvan. This seems a lost cause but, FWIW, I tested your first script from post 52 with PNG and JPEG files. I tested each file twice–once with “with icon” enabled and once with “with icon” disabled. All of the files were located on my boot drive and all of the files after processing by the script contained a width of 678 pixels.

The file sizes were:

PNG Original - 226 KB
PNG with Icon - 385 KB
PNG without Icon - 56 KB

JPEG Original - 3.9 MB
JPEG with Icon - 3 MB
JPEG without Icon - 89 KB

The increased file size with icons may not be surprising. In a different context Shane explained this as follows:

https://www.macscripter.net/viewtopic.php?pid=198928

@peavine

As I already wrote, I am stubborn.

I want to get the log history returned by “three sizes.scpt”.
In fact, as I enhanced it, now it’s “three sizes 1.scpt”

-- three sizes 1.scpt
-- Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 22:33:47

property mode : 1 -- try with the values 1, 2, 3
-- 1 --> alias
-- 2 --> «class furl»
-- 3 --> POSIX Path
--on open draggeditems

set draggedItems to choose file of type {"public.jpeg"} with multiple selections allowed
tell application "Image Events" to launch

repeat with currentFile in draggedItems
	if mode = 1 then
		set thePicture to currentFile as text
	else if mode = 2 then
		set thePicture to currentFile as «class furl» --> «class furl»
	else if mode = 3 then
		set thePicture to POSIX path of currentFile --> text
	end if
	
	set origSize to size of (info for currentFile)
	tell application "Image Events"
		if mode = 1 then
			set openedFile to open file thePicture
		else
			set openedFile to open thePicture
		end if
		--set fileLocation to the location of openedFile
		--set fileName to the name of openedFile
		set wantedSize to 800
		set newPath to my stamp(currentFile, wantedSize)
		set origDimensions to dimensions of openedFile
		set origResolution to resolution of openedFile
		scale openedFile to size wantedSize
		save openedFile in newPath with icon
		close openedFile
		set openedFile to open file newPath
		set newDimensions to dimensions of openedFile
		set newResolution to resolution of openedFile
		close openedFile
	end tell
	set newSize800 to size of (info for file newPath)
	tell me to display dialog "origSize : " & origSize & " bytes" & linefeed & "origDimensions : " & my recolle(origDimensions, ", ") & linefeed & "origResolution : " & my recolle(origResolution, ", ") & linefeed & "newDimensions : " & my recolle(newDimensions, ", ") & linefeed & "newResolution : " & my recolle(newResolution, ", ") & linefeed & "newSize800 : " & newSize800 & " bytes" & linefeed
	
	tell application "Image Events"
		if mode = 1 then
			set openedFile to open file thePicture
		else
			set openedFile to open thePicture
		end if
		--set fileLocation to the location of openedFile
		--set fileName to the name of openedFile
		set wantedSize to 1600
		set newPath to my stamp(currentFile, wantedSize)
		scale openedFile to size wantedSize
		save openedFile in newPath with icon
		close openedFile
		set openedFile to open file newPath
		set newDimensions to dimensions of openedFile
		set newResolution to resolution of openedFile
		close openedFile
	end tell
	set newSize1600 to size of (info for file newPath)
	tell me to display dialog "origSize : " & origSize & " bytes" & linefeed & "origDimensions : " & my recolle(origDimensions, ", ") & linefeed & "origResolution : " & my recolle(origResolution, ", ") & linefeed & "newDimensions : " & my recolle(newDimensions, ", ") & linefeed & "newResolution : " & my recolle(newResolution, ", ") & linefeed & "newSize1600 : " & newSize1600 & " bytes" & linefeed
	
	tell application "Image Events"
		if mode = 1 then
			set openedFile to open file thePicture
		else
			set openedFile to open thePicture
		end if
		--set fileLocation to the location of openedFile
		--set fileName to the name of openedFile
		set wantedSize to 3200
		set newPath to my stamp(currentFile, wantedSize)
		scale openedFile to size wantedSize
		save openedFile in newPath with icon
		close openedFile
		set openedFile to open file newPath
		set newDimensions to dimensions of openedFile
		set newResolution to resolution of openedFile
		close openedFile
	end tell
	set newSize3200 to size of (info for file newPath)
	tell me to display dialog "origSize : " & origSize & " bytes" & linefeed & "origDimensions : " & my recolle(origDimensions, ", ") & linefeed & "origResolution : " & my recolle(origResolution, ", ") & linefeed & "newDimensions : " & my recolle(newDimensions, ", ") & linefeed & "newResolution : " & my recolle(newResolution, ", ") & linefeed & "newSize3200 : " & newSize3200 & " bytes" & linefeed
end repeat
--end open

on stamp(anAlias, theSize)
	set theExt to name extension of (info for anAlias)
	tell (current date) to set theStamp to (((its year) * 10000 + (its month) * 100 + (its day)) as text) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
	set newPath to text 1 thru -(2 + (count theExt)) of (anAlias as string) & "_" & theStamp & "_" & theSize & "." & theExt
	return newPath
end stamp

#=====
on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle
#=====

What is really puzzling me is the fact that changeAgent sent me a video in which I see the droplet whose every instructions are disabled which execute the instruction triggering choose file.
I sent it to Shane Stanley hoping that he may explain that.
I hope that changeAgent did not made a mix of different videos to fool me but honestly I’m wondering.

Since the beginning I’m puzzled by what is described so, when I saw that the original file has a large block of null bytes at its end, I thought that it was the explanation. But some times after, when I saw that the size was correctly changed on the original file, I assumed that the supposed oddity was specific to Catalina, an OS with so many anomalies that a new one would not be surprising (in French we say “On ne prête qu’aux riches”).

Time was not completely wasted.
Now, everybody here know how to remove easily the extraneous null bytes from the end of jpeg files :wink:

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 24 mai 2020 22:48:24

Given the OP is primarily interested in file size, here’s another approach. In this case you pass not only a maximum height/width, but also a target file size in bytes. The script will rescale the pic and try with a low compression factor of 0.8 (scale is 0.0 to 1.0). If the result was too big, it will reduce the compression factor by 10% and try again, repeating until the file size is below the limit, or the compression factor hits 0.2 (point of diminishing returns).

use scripting additions
use framework "Foundation"
use framework "AppKit"

on resizedJpegFromPath:imagePath maxHeightOrWidth:maxDim targetBytes:maxBytes
	set imagePath to current application's NSString's stringWithString:imagePath
	set outPath to (imagePath's stringByDeletingPathExtension()'s stringByAppendingString:"-out")
	set outPath to outPath's stringByAppendingPathExtension:"jpg"
	-- Get the contents of the passed picture
	set theImageRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:imagePath -- load the file 
	set theClip to current application's NSPasteboard's generalPasteboard()
	-- Extract its original size
	set oldHeight to theImageRep's pixelsHigh()
	set oldWidth to theImageRep's pixelsWide()
	if oldWidth > oldHeight then
		set theWidth to maxDim
		set theHeight to oldHeight * maxDim / oldWidth
	else
		set theHeight to maxDim
		set theWidth to oldWidth * maxDim / oldHeight
	end if
	set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:theWidth pixelsHigh:theHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:yes isPlanar:false colorSpaceName:(current application's NSDeviceRGBColorSpace) bytesPerRow:0 bitsPerPixel:32)
	-- store the existing graphics context
	current application's NSGraphicsContext's saveGraphicsState()
	-- set graphics context to new context based on the new bitmapImageRep
	current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep)
	theImageRep's drawInRect:{origin:{x:0, y:0}, |size|:{width:theWidth, height:theHeight}} fromRect:(current application's NSZeroRect) operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:false hints:(missing value)
	-- restore state
	current application's NSGraphicsContext's restoreGraphicsState()
	set compFactor to 0.8 -- starting compression value
	set compMax to 0.2 -- compression limit
	repeat
		set theData to newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:compFactor}
		if compFactor > compMax and theData's |length|() > maxBytes then
			-- too big, so try with more compression
			set compFactor to compFactor * 0.9
		else -- give up
			exit repeat
		end if
	end repeat
	theData's writeToFile:outPath atomically:true
end resizedJpegFromPath:maxHeightOrWidth:targetBytes:

set anImage to choose file of type {"public.png", "public.tiff", "public.jpeg"}
my resizedJpegFromPath:(POSIX path of anImage) maxHeightOrWidth:800 targetBytes:100000

good morning I am back on line.

Yvan if I was that clever, to rig the video, I did not need help with this script. :-)) Indeed, it is unedited footage, only shrunk to a smaller size to be able to send it in an email. Scouts honour.

Shane your script works. It shrinks a picture from 2.2MB to 86KB.

Is there a way to make it in to a droplet? And in what line do I change the size it shrinks the picture in to?

Yvan good morning.

Your script makes an error.

Can’t get file “Seva Server:Users:ganesh:Desktop:3_20200525_101434_800.jpg” of application “Image Events”.

The log said:

tell application “Script Editor”
choose file of type {“public.jpeg”} with multiple selections allowed
→ {alias “Seva Server:Users:ganesh:Desktop:3.jpg”}
end tell
tell application “Image Events”
launch
end tell
tell current application
info for alias “Seva Server:Users:ganesh:Desktop:3.jpg”
→ {name:“3.jpg”, creation date:date “Monday, 25 May 2020 at 09:15:20”, modification date:date “Monday, 25 May 2020 at 09:15:20”, size:2218263, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:“jpg”, displayed name:“3.jpg”, default application:alias “Seva Server:System:Applications:Preview.app:”, kind:“JPEG image”, file type:“file creator:“type identifier:“public.jpeg”, locked:false, busy status:false, short version:””, long version:“”}
end tell
tell application “Image Events”
open file “Seva Server:Users:ganesh:Desktop:3.jpg”
→ image “3.jpg”
end tell
tell current application
info for alias “Seva Server:Users:ganesh:Desktop:3.jpg”
→ {name:“3.jpg”, creation date:date “Monday, 25 May 2020 at 09:15:20”, modification date:date “Monday, 25 May 2020 at 09:15:20”, size:2218263, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:“jpg”, displayed name:“3.jpg”, default application:alias “Seva Server:System:Applications:Preview.app:”, kind:“JPEG image”, file type:“file creator:“type identifier:“public.jpeg”, locked:false, busy status:false, short version:””, long version:“”}
current date
→ date “Monday, 25 May 2020 at 10:15:18”
end tell
tell application “Image Events”
get dimensions of image “3.jpg”
→ {}
get resolution of image “3.jpg”
→ {}
scale image “3.jpg” to size 800
save image “3.jpg” in “Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg” with icon
→ missing value
close image “3.jpg”
open file “Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg”
→ error number -1728 from file “Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg”
Result:
error “Image Events got an error: Can’t get file "Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg".” number -1728 from file “Seva Server:Users:ganesh:Desktop:3_20200525_101518_800.jpg”

PS I am testing presently on a different 10.15 machine.

Thank you

Sorry, what you report does not match what other users get under 10.15 with the same script.
As I am not a diviner it is not possible for me to guess what exotic adjustment was made on your machine.
This is the first time this has happened but I have to give up.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 25 mai 2020 11:33:38

Yvan, I know you have no crystal ball. I am using a Mac mini 2020 to test on this morning, that has a fresh 10.15 install (2 weeks ago) and the latest update to 10.15.4.

There are non what so ever exotic adjustments on it. Zero. There are no applications running on it that are not Mac Native and of those only a few. It is my blind server and mainly used for backup storage and sending out automatic mails via the native app Mail.

I switched to the MM as I have been testing so far on an external HD running 10.15.4 on my MBP. I thought this might influence stuff negatively.

Could the error be in the fact that I run an Englisch OS version and you a French?

PS.
I can still test later today if the same error happens on the other machine.
Would this be helpful?

Yvan, I have fired up the MBP with the external HD.

Your script runs there and makes 3 pictures.

The original is 1.8 M and your script makes 3 pictures of 2.2 – 2.9 – 3.7 MB. As well as larger icons.

The script doesn’t rely upon localized features.
What I know is that Catalina requires some specific settings to be able do achieve some tasks.
As I can’t install this system, I am unable to list those settings. I just know that they mainly are supposed to give some permissions to the scripts.

Back to the applet which you sent me.
I really don’t understand how you were able to create such a mess.
Your package contain three copies of the script.
It’s normal for a droplet created with Script Debugger.
What is odd is that these versions don’t match.
What appears when we ask Script Editor to open the script is the content of the embedded file named “main.rtf” but, what is executed in the content of the embedded file named “main.scpt” (which is identical to what is in the embedded file named “main.recover.rtf”).

Please, open your applet in Script Editor
select all
create a new empty script
paste in it
save as “4Yvan.app”
then drag and drop a jpeg upon it.
With this clean app you will see that what I wrote is the normal behavior.
As I can’t explain what you did to build the foolish applet I think that the only thing to do is to trash it and quickly empty the trash.

If somebody may describe the settings required by Catalina, maybe you will solve your problem.
I apologize but for me, GAME OVER.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 25 mai 2020 13:46:21

So Yvan sent me a copy of the script. The explanation is that the script you saved is not commented out, but the version that Script Editor auto-saved was made after the script was commented out. So when you opened the script again you saw the last auto-saved version, but the document was still dirty (a black dot in the red button in the title bar). However, that version isn’t the version that runs when you double-click.I suspect that somehow something has got damaged along the line after that.

The moral of the story: always save, never rely on auto-save.

Add this to the script:

on open draggedItems
	repeat with currentFile in draggedItems
		-- change targetBytes value to max file size in bytes
		(my resizedJpegFromPath:(POSIX path of currentFile) maxHeightOrWidth:800 targetBytes:100000)
	end repeat
end open

Change that 100000 to however many bytes is your limit.

Thanks Shane learning all the time! much appreciated.

Yes, I know this and here I am complete sure all is well. All my other scripts run flawlessly and all permissions in ‘Privacy’ tab are given.

Neither do I but I think Shane expained how it possibly could have happened.

I did that, and hate to say it does not work.

I think my settings are correct in the system. However should anybody have a tip as to what to check I love to hear.

I sincerely apologise if I upset you. I might not be the best AS scripter (I know I am not) but at no time did I intently try to upset the system. I am enormously grateful for the help you and others gave and have given me in the past solving AS challenges. Once again very sorry for the mess.