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

Thank you for this feedback.

May you explain what is this group of instructions supposed to achieve ?

 tell application "Finder"
        set the name of file fileName of fileLocation to (fileName)
end tell

At first look, it seems to be useless but maybe I missed something.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 22 mai 2020 15:12:20

Yvan, I had to fire up the test setting again and tested the script one more time and it stopped working. I have no idea as to why! Frustrating to say the least.

Here is what I did. I tested the script in new testing setup while we were ticking back and forth. Made it into an application and it worked. I still have these, and they still work.

I than made new ones for the folder where I normally keep them and did not test. Now because of your question I had a look and discovered that they do not work. If I paste the script directly in to a new window and save it as a App. It does not work.

Wow, I am stumped. Any ideas?

BTW Image Events still has full disk access.

Here some pics.

https://ibb.co/Vv71wmj

https://ibb.co/RCcScCG

In your screenshot I can’t see what is certainly the culprit.

on open draggeditems
   repeat with currentFile in draggeditems
       tell application "Image Events"
           set openedFile to open (currentFile as alias) --<<<< I don't see the end of this instruction
           
           set fileLocation to the location of openedFile
           set fileName to the name of openedFile

If you are using (currentFile as alias) it’s not surprising that it fail.

Peavine carefully urged you to use

set openedFile to open file (currentFile as string)

because under Catalina, Image Events is unable to work with aliases.

I wish to add that, even if it worked in the past, the original syntax was bad too

draggeditems is a list of aliases
currentFile is an alias so, coercing it into an alias make no real sense.
In old times the correct syntax was : set openedFile to open currentFile

This version must work

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)
			
			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

I guess that the two alternate versions listed below work too but I can’t test them under Catalina.

on open draggeditems
	repeat with currentFile in draggeditems
		tell application "Image Events" to launch
		set POSIXPath to POSIX path of currentFile
		tell application "Image Events"
			set openedFile to open POSIXPath
			
			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
on open draggeditems
	tell application "Image Events" to launch
	repeat with currentFile in draggeditems
		set theFile to currentFile as «class furl»
		tell application "Image Events"
			set openedFile to open 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

If it prove to work, the late one is my preferred choice because «class furl» is the class of object which is used now by most tools.
And of course, I’m always waiting your explanations about the three instructions which I deliberately disabled.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 22 mai 2020 18:15:37

Yvan, thanks, and first off, all the suggested scripts you post make the image bigger.

My present challenge is that the script works (see both below) in the test version I made. If I make a new one it does not work. So, if I copy and paste the script in a new AS window, save it as an App, it gives the errors I posted in the my last post.

So, this one works (yes with the alias and I will change it once the present problem is solved)

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

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 2000
			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

and this one too

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

I will now be of-line till tomorrow.

Always under 10.13.6, I made numerous tests and discovered an interesting feature.

I saved 3 versions of this script:

tell application "Image Events"
	launch
end tell
property mode : 3 -- try with the values 1, 2, 3
-- 1 --> alias
-- 2 --> «class furl»
-- 3 --> POSIX Path
on open draggeditems
	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
		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
			(*
			scale openedFile to size 800
			save openedFile with icon
			*)
			close openedFile
		end tell
		tell me to say "It worked"
		tell application "Finder"
			set the name of file fileName of fileLocation to (fileName)
		end tell
	end repeat
end open

With a single change : the value of the property named mode.
The three versions work flawlessly.
BUT, here is the discovery, to get such behavior I was forced to save a script built from a blank document.
At first, I created version #1.app in which mode was set to 1.
I applied cmd + shift + S to create a new copy in which I set mode to 2 and saved as version #2.app
Damned, when I try to drag and drop a picture upon the app’s icon, the picture was not treated and its icon was moved on the desktop.
So I deleted version #2.app, opened version #1.app, select all, copy, paste in a new blank window and at last, saved as version #2.app.
Bingo, this time, drag and drop behaved flawlessly.

I didn’t really built droplet for years so I don’t know if this “surprising” behavior is new but at least it may explain what you got.

Given that, I decided to build new versions which, from my point of view, are cleaner.


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

on open draggeditems
	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
		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
			
			scale openedFile to size 800
			save openedFile with icon
			
			close openedFile
		end tell

		(*
		tell me to say "It worked"
		tell application "Finder"
			set the name of file fileName of fileLocation to (fileName)
		end tell
		*)
	end repeat
end open

Of course, the “surprising” protocol was required, but the three new versions behaved flawlessly.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 11:41:20

Yvan I am not at the machine but will be later this PM. Will test and report back.

and interesting your discovery. makes me feel less stupid. :slight_smile:

I’ve lost track of this thread, and this may be known, but the increased file size could be a result of the following line:

save openedFile with icon

Change it as follows to see reduced file sizes:

save openedFile

In my testing with a 270 KB PNG original, the output file contained 410 KB with icon and 87 KB without icon. This is with Yvan’s must-work script from post 25.

Peavine, greetings.

Changing that line makes no difference. As before, a 1.8 MB jpeg becomes 2.2MB. A 3.2MB png stays the same size. All that happens is that the size of the icon picture becomes bigger.

I am really stumped that it works on your end and not on mine.

I am on OS 10.15.4 on a MM 2020.

I don’t understand that either. There’s some other factor at work that we are missing.

I understand that you want to use Image Events but have your tried my script from post 13. It uses sips and this could be helpful to understand what’s happening. On my Catalina computer, this script worked with PNG and JPEG files on boot and external drives.

Yvan I am back at the machine. Tested. And as before no cigar. A 1.8 MB jpeg becomes 2.2MB. A 3.2MB png stays the same size. All that happens is that the size of the icon picture becomes bigger.

Why would it not work?

Peavine, as to post 13.
It works and it does not.

It changes a png from 3.2MB to 590KB regardless of what we put in the sips dialog.

And an 1.8MB jpeg reduces to 45kb with the script below.

As said, it even works like this and has the same result.

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 "" & draggeditems
	
end open

May you test this one and post what is reported?

property mode : 3 -- try with the values 1, 2, 3
-- 1 --> alias
-- 2 --> «class furl»
-- 3 --> POSIX Path
on open draggeditems
	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
		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 origDimensions to dimensions of openedFile
			set origResolution to resolution of openedFile
			scale openedFile to size 800
			save openedFile with icon
			set newDimensions to dimensions of openedFile
			set newResolution to resolution of openedFile
			close openedFile
		end tell
		tell me to display dialog "origDimensions : " & my recolle(origDimensions, ", ") & linefeed & "origResolution : " & my recolle(origResolution, ", ") & linefeed & "newDimensions : " & my recolle(newDimensions, ", ") & linefeed & "newResolution : " & my recolle(newResolution, ", ")
		(*
		tell application "Finder"
			set the name of file fileName of fileLocation to (fileName)
		end tell
*)
	end repeat
end open

#=====
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
#=====

Here I got:
picture #1
origDimensions : 1725, 446
origResolution : 144,0, 144,0
newDimensions : 800, 207
newResolution : 144,0, 144,0

picture #2
origDimensions : 3104, 1746
origResolution : 72,0, 72,0
newDimensions : 800, 450
newResolution : 72,0, 72,0

Don’t worry, the resolution is displayed with the local (comma) decimal separator.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 16:49:15

I don’t know what happening then. Sorry I couldn’t help.

May you run :

on open draggeditems
	--set draggeditems to choose file of type {"public.jpeg"} with multiple selections allowed
	set text1 to my recolle(draggeditems, linefeed)
	repeat with aFile in draggeditems
		set contents of aFile to quoted form of POSIX path of aFile & space
	end repeat
	set text2 to my recolle(draggeditems, linefeed)
	
	display dialog text1 & linefeed & text2
	--do shell script "sips --resampleHeightWidthMax 800 " & draggeditems
end open
#=====

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

#=====

and report what you got ?

On my iMac (10.13.6) I got :

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
‘/Users//Desktop/DSC_0257 - opposite.jpg’
'/Users/
/Desktop/DSC_0257 - rotated.jpg’
‘/Users//Desktop/DSC_0257 - upDown.jpg’
'/Users/
/Desktop/DSC_0257.JPG’

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 17:53:39

Yvan (post 34) here is what it reports for a jpeg pic:

origDimensions : 3264, 1836
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0

however the pic went from 1.8 to 2.2 MB. So, it shrunk its size as in dimensions but enlarged the size as in KB.

For a png a similar thing happens. The size (MB) stays the same and it reports:

origDimensions : 1920, 1080
origResolution : 72.0, 72.0
newDimensions : 800, 450
newResolution : 72.0, 72.0

The aim of my original script was to redse KB. So, the 1.8 MB became like 110 KB.

Yvan as to the script in post 36, nothing happens. Well I get a box to click.

OS 10.15 test:Users:e:Desktop:1 copy 5.png
‘/Users/e/Desktop/1 copy 5.png’

So, it did what it was supposed to do, If you look at the script in message 36, the call to SIPS was deliberately disabled.

Now that we know that the needed infos are correctly passed, try the version with the call to SIPS enabled:

on open draggeditems
	--set draggeditems to choose file of type {"public.jpeg"} with multiple selections allowed
	set text1 to my recolle(draggeditems, linefeed)
	repeat with aFile in draggeditems
		set contents of aFile to quoted form of POSIX path of aFile & space
	end repeat
	set text2 to my recolle(draggeditems, linefeed)
	
	display dialog text1 & linefeed & text2
	do shell script "sips --resampleHeightWidthMax 800 " & draggeditems
end open
#=====

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

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 19:08:43

May you send one or two of your pictures to my mail address : <koenigyvan mac com>

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 mai 2020 19:10:30

Same result as before.

send.