Jump to content

Paste clipboard to file

Recommended Posts

Welcome @tomvo,


37 minutes ago, tomvo said:

if I do a paste action in finder and the clipboard contains an image past it as a new image file


If you paste via the Finder, Alfred won’t interfere. I know the request sounds simple, but in technical terms it is not. It’s an interesting idea, though, so you may wish to suggest it to Apple via the Feedback Assistant app.


WebScreenshot has an option to save the clipboard image to the Desktop.

Link to comment

well I was hoping to based on the contenttype of the clipboard dynamically maybe trigger a script like this

Ideally there is a way to have the variables come from alfred


filename="Screen Shot $(date +%Y-%m-%d\ at\ %H.%M.%S).png"
if [ $# -ne 0 ]; then
if [[ -d $1 ]]; then
if [ "$1" != "." ]; then folder=$1; fi
a=$(dirname "$1")
b=$(basename "$1" .png)
if [ "$b" != "" ]; then filename=$b.png; fi
if [ "$a" != "." ]; then folder=$a; fi
osascript -e "tell application \"System Events\" to ¬
write (the clipboard as «class PNGf») to ¬
(make new file at folder \"$folder\" ¬
with properties {name:\"$filename\"})"
Link to comment

That would require Alfred to intercept all your pastes, and intercepting (and changing ⌘V) could lead to several issues and unexpected behaviour.


An alternative way to go about it is to set up a Hotkey Trigger and connect it to your code in a Run Script Action. You cannot use ⌘V as the shortcut though, as per above.


pwd also won’t work because that’s in the shell, it’s not related to the Finder. But there is an Automation Task to get the path of the frontmost Finder window that you can run beforehand.


Edited by vitor
Link to comment
10 hours ago, vitor said:

’t work because that’s in the shell, it’s not related to the Find

This is the flow I end up with, any suggestions to figure out what's on the clipboard, to make the handling different for text or images ?



Link to comment

In /usr/bin/osascript (JavaScript):





If you e.g. take a screenshot directly to the clipboard, that will by default return public.png. Other formats are possible, it depends on the case. To see every type of what’s on the clipboard in JXA:



$.NSPasteboard.generalPasteboard.pasteboardItems.js[0].types.js.map(c => c.js)


Link to comment
  • vitor changed the title to Paste clipboard to file

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...