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

I have the following script.

tell application "Image Events"
	launch
end tell

on open draggeditems
	repeat with currentFile in draggeditems
		tell application "Image Events"
			set openedFile to open (currentFile as alias)
			
			set fileLocation to the location of openedFile
			set fileName to the name of openedFile
			
			scale openedFile to size 800
			save openedFile with icon
			close openedFile
		end tell
		
		tell application "Finder"
			set the name of file fileName of fileLocation to ¬
				(fileName)
		end tell
	end repeat
end open

It worked fine under 10.13 but now that I moved to 10.15 it does not. See pic for error.

https://pasteboard.co/J9gwh9B.png

Any idea as to how to fix?

Image Events, like System Events, no longer works reliably with aliases, and that could be the cause of the issue you are experiencing. For more information on this issue, and some workarounds, see:

https://macscripter.net/viewtopic.php?pid=199787

The following worked for me:

tell application "Image Events"
	launch
end tell

on open draggeditems
	repeat with currentFile in draggeditems
		tell application "Image Events"
			set theFile to currentFile as text
			set openedFile to open file theFile
			
			set fileLocation to the location of openedFile
			set fileName to the name of openedFile
			
			scale openedFile to size 800
			save openedFile with icon
			close openedFile
		end tell
		
		tell application "Finder"
			set the name of file fileName of fileLocation to ¬
				(fileName)
		end tell
	end repeat
end open

As a starting point, run this script:

set currentfile to choose file of type {"public.jpeg"}

tell application "Image Events"
	set openedFile to open (currentfile as alias) --> image "20190304_205111+.jpg"
	set fileLocation to the location of openedFile --> folder "SSD 1000:Users:**********:Desktop:images:"
	set fileName to the name of openedFile --> "20190304_205111+.jpg"
end tell

The comments show what is returned in 10.13.6

Your screenshot let me think that under Catalina you get:

set fileLocation to the location of openedFile --> missing value

Now, I will try to describe what you really do.

tell application "Finder"
set refToFile to file fileName of fileLocation -- which is just an other way to point to currentfile
set name of refToFile to (fileName)
end tell

If, as I guess, “Image Events” returns missing value for fileLocation,
your code is logically unable to build a reference to the original file but what need to rebuild what you already know ?

tell application "Finder"
set name of currentfile to (fileName)
end tell

or

tell application "Finder"
set name of (currentfile as alias) to (fileName)
end tell

would do the job.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 20 mai 2020 18:51:07

Thanks peavine and Yvan

I am away from the 10.15 machine (now on 10.13), so as soon as I am back there I will give it a go.

peavine thanks.

just tested and it does not shrink the image. however it does not return an error.

Yvan, I am testing your post and at the first script you suggest I get, see pic.

I am also not sure I understand the rest, but wanted to report as I figured I might get it as I move along.

https://ibb.co/7R2hQ6T

ChangeAgent. The following is a slightly revised version of my script–it simplifies the coercion of alias to text and eliminates the save-with-icon option.

tell application "Image Events"
	launch
end tell

on open draggeditems
	repeat with currentFile in draggeditems
		tell application "Image Events"
			set openedFile to open file (currentFile as text)
			
			set fileLocation to the location of openedFile
			set fileName to the name of openedFile
			
			scale openedFile to size 800
			save openedFile
			close openedFile
		end tell
		
		tell application "Finder"
			set the name of file fileName of fileLocation to (fileName)
		end tell
	end repeat
end open

As a test, I saved the script to the desktop as an application. I then dragged a 3.9-MB JPEG file from a Finder window onto the application icon. The 3.9-MB JPEG file now showed a file size of 126 KB, and the Preview app showed the image dimensions as 800 pixels wide. Are you seeing something different?

mmm, peavine.

It runs fine but does not change the size. Odd. I tried with a 1.8 MB jpeg and a 3.2MB png.

I do not understand this, do you? I use OS 10.15.4 and Script Editor Version 2.11 (208)

Thank you,
it’s worse than what I guessed,
the instruction

set openedFile to open (currentfile as alias)

set the variable openedFile to missing value and it’s what is reported and is perfectly described in the right pane of Script Debugger.

peavine which may run Catalina gave you the syntax required by this system but he missed what I tried to explain.

What he posted may be re-phrased as:

tell application "Image Events"
	launch
end tell

on open draggeditems
	repeat with currentFile in draggeditems -- here currentFile IS an alias
		tell application "Image Events"
			set openedFile to open file (currentFile as text)

			-- set fileLocation to the location of openedFile	-- DISABLED		
			set fileName to the name of openedFile
			
			scale openedFile to size 800
			save openedFile
			close openedFile
		end tell
		
		tell application "Finder"
			set the name of currentFile to (fileName) -- EDITED
		end tell
	end repeat
end open

And with this new spelling, it appears clearly that what you ask to the Finder is perfectly useless.

The script may be reduced to:

tell application "Image Events"
	launch
end tell

on open draggeditems
	repeat with currentFile in draggeditems -- here currentFile IS an alias
		tell application "Image Events"
			set openedFile to open file (currentFile as text)
			
			set fileName to the name of openedFile
			
			scale openedFile to size 800
			save openedFile
			close openedFile
		end tell
	end repeat
end open

Running 10.13.6, I applied this script to a file whose size was 1746 x 3104 pixels and the treated file is now a 450 x 800 pixels one. Of course I don’t know what is achieved under 10.15.4.

To be honest, I think tha the instructions

tell application "Image Events"
	launch
end tell

may be removed too.

My understanding is tha peavine misunderstood your question.
With its code, you resize the file so that its greater dimension becomes 800 pixels.
So if you pass a file whose size was 1280 x 720 you will get a 800 x 450 pixels one which as I read your question is not what you wanted.
I understood that you wanted it to be a 1422 x 800 one.

In fact peavine understood what you posted, not what you had in mind.
On my side, I mixed the contents of two threads, this one and https://macscripter.net/viewtopic.php?id=47670 so by chance I thought to what you had in mind.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 21 mai 2020 17:21:47

Yvan. I just tried to get the OP’s script to work on my Catalina computer. I didn’t carefully review what you wrote–sorry.

I agree that the Finder code does nothing. My knowledge of scripts of this sort is very limited but I would write the script as follows:

on open draggeditems
	tell application "Image Events"
		launch
		
		repeat with currentFile in draggeditems -- here currentFile IS an alias
			set openedFile to open file (currentFile as text)
			scale openedFile to size 800
			save openedFile
			close openedFile
		end repeat
		
	end tell
end open

This script works on my test JPEG file but not on a PNG file. I’m not sure of the reason for that but will look into this matter later.

As regards the size of the resized image, I don’t know if the OP wants to reduce the longer or the shorter side of the original image to 800 pixels. That seems a peripheral issue right now, as the OP can’t get the script to do anything. However, FWIW, my test image was 4032 by 3024 and became 800 by 600 after running it through my script.

It seems that you missed that the OP wrote:

I’m quite sure that Preview states that the image is 450 pixels high for a width of 800 pixels when he hoped to get a 800 pixels height for a 1422 pixels width.
With your example it means that 4032 (width) x 3024 (height) would become 1067 width) x 800 (height).
For sure, it’s not what the original script would have returned under High Sierra.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 21 mai 2020 18:49:16

Yvan thanks.

I ran your script, and nothing happens. The pic is by the way 3024 × 4032, 1.8 MB

My aim, and this is what the original script did, is to shrink the image in size. So, to about 100 mb. It is what in 10.13 the quart filters do. But they too seem to have disappeared in 10.15.

Yvan. I think I wrote that not the OP. Anyways, the OP might try the following, which worked with both JPEG and PNG files on my computer. The option resampleHeightWidthMax can be changed to resampleHeight or resampleWidth if desired.

on open draggeditems
	
	repeat with aFile in draggeditems
		set contents of aFile to quoted form of POSIX path of aFile & space
	end repeat
	
	do shell script "sips --resampleHeightWidthMax 800 " & draggeditems
	
end open

Oops, it seems that I am tired.

What is returned by this script under Catalina ?

set theFile to choose file of type {"public.png", "public.jpeg"}

tell application "Image Events"
	set openedFile to open file (theFile as string)
	properties of openedFile

	scale openedFile to size 800
	save openedFile with icon
	close openedFile
	
	set openedFile to open file (theFile as string) -- with Catalina
	properties of openedFile
end tell

Here I got :


Don't click that, it's a log history

(case 1 .png)
tell application "Script Editor"
	choose file of type {"public.png", "public.jpeg"}
		--> alias "SSD 1000:Users:**********:Desktop:##29381 copie.png"
end tell
tell application "Image Events"
	open file "SSD 1000:Users:**********:Desktop:##29381 copie.png"
		--> image "##29381 copie.png"
	get properties of image "##29381 copie.png"
		--> {color space:RGB, image file:file "SSD 1000:Users:**********:Desktop:##29381 copie.png", bit depth:millions of colors, dimensions:{1023, 658}, location:folder "SSD 1000:Users:**********:Desktop:", embedded profile:profile "iMac" of image "##29381 copie.png", file type:PNG, class:image, name:"##29381 copie.png", resolution:{72.0, 72.0}}
	scale image "##29381 copie.png" to size 800
	save image "##29381 copie.png" with icon
		--> file "SSD 1000:Users:**********:Desktop:##29381 copie.png"
	close image "##29381 copie.png"
	open file "SSD 1000:Users:**********:Desktop:##29381 copie.png"
		--> image "##29381 copie.png"
	get properties of image "##29381 copie.png"
		--> {color space:RGB, image file:file "SSD 1000:Users:**********:Desktop:##29381 copie.png", bit depth:millions of colors, dimensions:{800, 514}, location:folder "SSD 1000:Users:**********:Desktop:", embedded profile:profile "iMac" of image "##29381 copie.png", file type:PNG, class:image, name:"##29381 copie.png", resolution:{72.0, 72.0}}
end tell

#-----------

(case 2 .jpg)
tell application "Script Editor"
	choose file of type {"public.png", "public.jpeg"}
		--> alias "SSD 1000:Users:**********:Desktop:##29378.jpg"
end tell
tell application "Image Events"
	open file "SSD 1000:Users:**********:Desktop:##29378.jpg"
		--> image "##29378.jpg"
	get properties of image "##29378.jpg"
		--> {color space:RGB, image file:file "SSD 1000:Users:**********:Desktop:##29378.jpg", bit depth:millions of colors, dimensions:{1200, 1600}, location:folder "SSD 1000:Users:**********:Desktop:", embedded profile:missing value, file type:JPEG, class:image, name:"##29378.jpg", resolution:{72.0, 72.0}}
	scale image "##29378.jpg" to size 800
	save image "##29378.jpg" with icon
		--> file "SSD 1000:Users:**********:Desktop:##29378.jpg"
	close image "##29378.jpg"
	open file "SSD 1000:Users:**********:Desktop:##29378.jpg"
		--> image "##29378.jpg"
	get properties of image "##29378.jpg"
		--> {color space:RGB, image file:file "SSD 1000:Users:**********:Desktop:##29378.jpg", bit depth:millions of colors, dimensions:{600, 800}, location:folder "SSD 1000:Users:**********:Desktop:", embedded profile:profile "sRGB IEC61966-2.1" of image "##29378.jpg", file type:JPEG, class:image, name:"##29378.jpg", resolution:{72.0, 72.0}}
end tell

Under 10.13.6, Image Events works well with «class furl» objects. Is it the same under Catalina ?

set theFile to choose file of type {"public.png", "public.jpeg"}
set theFile to theFile as «class furl»
tell application "Image Events"
	set openedFile to open theFile
	
	properties of openedFile
	scale openedFile to size 800
	save openedFile with icon
	close openedFile
	
	set openedFile to open theFile
	properties of openedFile
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 21 mai 2020 20:45:53

Yvan. Your scripts in post 14 and 15 work on image files on my boot drive but not an external drive, where they return:

The following is the only script that worked on the external drive:

set theFile to choose file of type {"public.png", "public.jpeg"}
set theFile to quoted form of POSIX path of theFile

do shell script "sips --resampleHeightWidthMax 800 " & theFile

Thank you.

Maybe it’s because insomnia strikes but I am surprised because, in www.mac.osxautomation.com I may read :
The Image Events application is used by AppleScript to control the SIPS architecture. It has no visual interface and presents no menus, windows, or dialogs for user interaction. It is intended to run invisibly as a background process, only accessible via AppleScript commands.

So I always thought that Image Events was able to do what SIPS does.

Here the script below grabs the size infos from a file stored on an external device using Image Events as well as extracting metadatas with ASObjC.

----------------------------------------------------------------
use AppleScript version "2.5" -- (10.11) or later
use framework "Foundation"
use scripting additions
----------------------------------------------------------------

set theFile to choose file of type {"public.png", "public.jpeg"}

set theFile to theFile as «class furl»

set POSIXPath to POSIX path of theFile
log POSIXPath -- to check that it's on an external device
tell application "Image Events"
	try
		set openedFile to open theFile -- a «class furl» object
		properties of openedFile
		close openedFile
	end try
	try
		set openedFile2 to open POSIXPath -- a POSIX Path
		properties of openedFile2
		close openedFile2
	end try
end tell

set thisNSURL to current application's NSURL's fileURLWithPath:POSIXPath
set nsMetaItem to current application's NSMetadataItem's alloc()'s initWithURL:thisNSURL
# Build a list of every available metadatas
set theMetadata to nsMetaItem's valuesForAttributes:(nsMetaItem's attributes())
return theMetadata as list

Here, under 10.13.6, the log history is :

tell application "Script Editor"
	choose file of type {"public.png", "public.jpeg"}
		--> alias "Aluice_250:Users:**********:DiskSpeedTest.png"
end tell
(*/Volumes/Aluice_250/Users/**********/DiskSpeedTest.png*)
tell application "Image Events"
	open file "Aluice_250:Users:**********:DiskSpeedTest.png"
		--> image "DiskSpeedTest.png"
	get properties of image "DiskSpeedTest.png"
		--> {color space:RGB, image file:file "Aluice_250:Users:**********:DiskSpeedTest.png", bit depth:millions of colors, 

dimensions:{825, 850}, 

location:folder "Aluice_250:Users:**********:", embedded profile:missing value, file type:PNG, class:image, name:"DiskSpeedTest.png", resolution:{72.0, 72.0}}
	close image "DiskSpeedTest.png"
	open "/Volumes/Aluice_250/Users/**********/DiskSpeedTest.png"
		--> image "DiskSpeedTest.png"
	get properties of image "DiskSpeedTest.png"
		--> {color space:RGB, image file:file "Aluice_250:Users:**********:DiskSpeedTest.png", bit depth:millions of colors, 

dimensions:{825, 850}, 

location:folder "Aluice_250:Users:**********:", embedded profile:missing value, file type:PNG, class:image, name:"DiskSpeedTest.png", resolution:{72.0, 72.0}}
	close image "DiskSpeedTest.png"
end tell
Résultat :
{{kMDItemFSContentChangeDate:date "lundi 11 avril 2011 à 22:57:31", kMDItemDateAdded_Ranking:date "mardi 9 décembre 2014 à 01:00:00", kMDItemFSTypeCode:0, 

kMDItemPixelHeight:850, 

kMDItemDisplayName:"DiskSpeedTest.png", kMDItemFSIsExtensionHidden:false, kMDItemFSLabel:0, kMDItemContentCreationDate:date "lundi 11 avril 2011 à 22:57:31", kMDItemContentTypeTree:{"public.png", "public.image", "public.data", "public.item", "public.content"}, kMDItemBitsPerSample:40, kMDItemInterestingDate_Ranking:date "lundi 11 avril 2011 à 02:00:00", kMDItemFSFinderFlags:0, kMDItemPixelCount:701250, kMDItemHasAlphaChannel:true, kMDItemResolutionHeightDPI:72, kMDItemFSSize:364246, kMDItemColorSpace:"RGB", kMDItemFSName:"DiskSpeedTest.png", kMDItemDateAdded:date "mardi 9 décembre 2014 à 20:16:50", kMDItemResolutionWidthDPI:72, kMDItemPhysicalSize:364544, kMDItemFSCreationDate:date "lundi 11 avril 2011 à 22:57:31", kMDItemContentCreationDate_Ranking:date "lundi 11 avril 2011 à 02:00:00", kMDItemFSCreatorCode:0, kMDItemInterestingDate_RankingRepaired:true, kMDItemOrientation:1, kMDItemFSInvisible:false, kMDItemKind:"Image PNG (Portable Network Graphics)", 

kMDItemPixelWidth:825, 

kMDItemFSOwnerUserID:501, kMDItemContentModificationDate:date "lundi 11 avril 2011 à 22:57:31", kMDItemContentType:"public.png", kMDItemLogicalSize:364246, kMDItemFSOwnerGroupID:20}}

I was aware that under Catalina, Image Events has problem with alias objects but not that it’s failing with files stored on external devices.

If it’s confirmed, it seems that it’s not a feature but an annoying bug.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 22 mai 2020 03:49:13

Have you granted Image Events Full Disk Access?

Thanks Shane. That was the problem.

Giving Image Events full disk access is not very straightforward:

https://darjeelingsteve.com/articles/Fixing-"Image-Events"-AppleScripts-Broken-in-macOS-10.15-Catalina.html

For Yvan, the output from your script in post 15 with a PNG file on the external drive:

I think you’re perhaps taking it a bit too literally. SIPS and Image Events appeared at the same time, and took advantage of the same underlying framework – I think that underlying framework is what is meant by the rather loose term “SIPS architecture” here. And it doesn’t mean each exposes all the same functionality, just that they both have access to it.