I have a few thumbnails that I would like to copy to the clipboard on 10.9. I have a really basic script that opens a Finder selection window, and sets the clipboard to the selection. But when I try to use command V to paste- nothing happens.
The desired result is to: select the item(s) via Finder selection, copy the selected items to the clipboard, then have the user type command v to paste the image into a Mail message.
I’ve tried a few different variations and the best I can do is get it to paste the file path. I need it to paste the actual image that the user selects. Any suggestions? Thanks!
set the_file to choose file
set the clipboard to the_file
get the clipboard --testing the clipboard
Save the following into an Automator service, and assign a keyboard shortcut through it thru the System Preferences panel → keyboard → shortcuts → services.
Edit
You select Finder as the target of the service when you save it in “Automator”, I chose a name of “Image to Clipboard” for it.
Do you know how I could get this to work with multiple files? It allows me to select multiples but it will error out on execution. I blended your answer with McUsrII’s like so:
try
set the clipboard to (read (choose file multiple selections allowed yes) as TIFF picture)
on error
tell application "SystemUIServer" to display dialog "Nothing selected" with title "Read image to clipboard" with icon stop buttons {"Cancel"} default button "Cancel"
end try
It allows me to select multiples but it will error out on execution.
Try this from your script editor window. It may be difficult to make a service out of this, because of the ui interaction.
If I were you, I’d rather run this script from the editor, or use the single one, or use the control-f4 / shift control-f4 window shortcuts (If you press the “fn” key when you adjust the volume), to flip between the front window of Finder and Mail, and drag multiple images over. (You can also drag images over onto the command bar icon of Mail to activate it.
Here is the script. It is untested.
set failed to true
tell application "SystemUIServer"
try
set theFileList to (choose file of type "jpg" multiple selections allowed yes)
set failed to false
on error
tell application "SystemUIServer" to display dialog "Nothing selected" with title "Read image(s) to clipboard and paste." with icon stop buttons {"Cancel"} default button "Cancel"
end try
end tell
if failed then
return
else
tell application "Mail" to activate
repeat with aFile in the theFileList
try
set the clipboard to (read (contents of aFile) as TIFF picture)
delay 0.2
tell application "System Events" to tell application process "Mail" to keystroke "v" using {command down}
delay 0.2
on error e number n
tell application "SystemUIServer" to display dialog "Something went wrong: " & e & ": " & n with title "Read image(s) to clipboard and paste." with icon stop buttons {"Cancel"} default button "Cancel"
exit repeat
end try
end repeat
end if
Sudo
This script was posted in reply to me in 2007 from a member named Blend 3. If you use the shift key when you copy, you can copy more than one image to the clipboard. It works very well on multiple Images as well as text. You will of course have to change the email address, content and subject to suit your email.
This is the Script.
tell application "Mail"
activate
set newMessage to make new outgoing message with properties {subject:"test", content:"test"}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:"My Email", address:" email@address.com"}
end tell
end tell
tell application "System Events"
tell process "Mail"
keystroke "v" using command down
end tell
end tell