conversion of a PNG file/image to a JPEG file/image with AppleScript

So I'm trying to convert a screenshot (PGN) on my desktop to a JPEG file. I'm using the save command from the Image Event application. I always run into the error -1700: unable to make type reference. Even when I execute the example from the developers.apple.com:

[Mac Automation Scripting Guide: Manipulating Images]

I also tried converting the alias object to a file object (set imagefile to theImage as «class furl»), but to no avail:


-- Prompt for an image


set theImageFile to choose file of type "public.image" with prompt ""


set theOutputFolder to (path to desktop folder as string)


-- Launch Image Events and open the image


do shell script "> $HOME'/Desktop/temp-01.jpg'"


tell application "Image Events"


launch


open theImageFile


set theImage to theImageFile


set target to "Macintosh HD:Users:siemhuijsman:Desktop:temp-01.jpg"


set imagefile to theImage as «class furl»


save imagefile as JPEG in target


close


log theImageFile


end tell


I would be much helped if somebody can explain the error that occurs and perhaps a way to get the job done.

Thank you in advance,


Siem Huijsman



MacBook Pro 16″, macOS 14.0

Posted on Oct 4, 2023 2:38 PM

Reply
4 replies

Oct 4, 2023 3:10 PM in response to siemhuijsman

AppleScript is good for scripting GUI apps, and other such.


It’s not something I’d usually choose for performing non-GUI-related tasks.


Here is the built-in graphics conversion tool, sips:


sips -s format [image type] [file name] --out [output file]


Here is an example of using the built-in shell command to perform the requested conversion.


sips --setProperty format jpeg Whatever.png --out Whatever.jpg


The next question here then becomes how you will call this conversion tool. The command can be invoked from AppleScript, if that is your wont. There are other ways to call a script.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

conversion of a PNG file/image to a JPEG file/image with AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.