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?
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.
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
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
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
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
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.
Thank you Shane.
If Image Events is able to apply to external devices when it’s granted Full Disk Access, the problem is solved.
At least if the info is available for every user.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 22 mai 2020 06:26:35
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.
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