Apple Intelligence now features Image Playground, Genmoji, Writing Tools enhancements, seamless support for ChatGPT, and visual intelligence.

Apple Intelligence has also begun language expansion with localized English support for Australia, Canada, Ireland, New Zealand, South Africa, and the U.K. Learn more >

You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to save a new jpg image from the clipboard

It seems like it should be simple but I can't find anywhere this has been documented.

I have an image on the clipboard and simply want to save it as a new image.

I've been using Image Events and I can get a file saved but it's always empty.

Can someone please post some sample code to do this?

imac 2.8, Mac OS X (10.5)

Posted on Mar 27, 2010 2:38 PM

Reply
3 replies

Mar 29, 2010 8:07 AM in response to Kablooie

I'm sure there's a more elegant way to script this, but here is a script I just wrote real quick that should at least give you a start to an alternate way of dealing with clipboard data without having to launch Preview...

<pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
title="Copy this code and paste it into your Script Editor application.">
--see if clipboard is a file
set filePath to ""
try
set clipPath to the clipboard as «class furl»
set filePath to clipPath as alias
end try
if filePath is not "" then
set newFile to getFileName("copied")
do shell script "cp " & quoted form of POSIX path of filePath & ¬
space & quoted form of POSIX path of newFile
return --end
end if
--see if clipboard is image data
set jpegDATA to ""
try
set jpegDATA to the clipboard as JPEG picture
end try
if jpegDATA is not "" then
set newFile to getFileName("new")
set theFile to open for access newFile with write permission
write jpegDATA to theFile
close access theFile
return --end
end if
beep 1
display dialog ¬
"No file or image data found on the clipboard." with icon ¬
note buttons {"Whatever"} default button 1
on getFileName(type)
choose file name with prompt ¬
"Select a name and location for the " & type & ¬
" jpeg:" default location (path to desktop) default name ¬
type & ".jpg"
end getFileName
</pre>

Hope this helps...

Mar 27, 2010 5:30 PM in response to Kablooie

Oops… I forgot that you also wanted to save the picture. The following script should save the picture as a JPEG file on your desktop:

try
*tell application "Preview" to activate*
*tell application "System Events" to tell process "Preview"*
*keystroke "n" using command down*
*repeat until window 2 exists* -- window 1 in a hidden window
*delay 0.25*
*end repeat*
*keystroke "s" using command down*
*delay 0.25*
*keystroke "d" using command down* -- save to desktop
*tell pop up button 1 of group 1 of sheet 1 of window 2*
click -- open the pop up button menu
*click menu item "JPEG" of menu 1* -- select "JPEG"
*end tell*
*keystroke return*
*end tell*
*end try*

Hope it can help.

How to save a new jpg image from the clipboard

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