tomvo Posted February 2, 2023 Share Posted February 2, 2023 I would like to , if I do a paste action in finder and the clipboard contains an image past it as a new image file (or if text as a txt file) directly in the directory Link to comment
vitor Posted February 2, 2023 Share Posted February 2, 2023 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
tomvo Posted February 2, 2023 Author Share Posted February 2, 2023 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 folder=$(pwd) 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 else a=$(dirname "$1") b=$(basename "$1" .png) if [ "$b" != "" ]; then filename=$b.png; fi if [ "$a" != "." ]; then folder=$a; fi fi 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
vitor Posted February 2, 2023 Share Posted February 2, 2023 (edited) 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 February 2, 2023 by vitor Link to comment
tomvo Posted February 3, 2023 Author Share Posted February 3, 2023 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
vitor Posted February 3, 2023 Share Posted February 3, 2023 In /usr/bin/osascript (JavaScript): ObjC.import("AppKit") $.NSPasteboard.generalPasteboard.pasteboardItems.js[0].types.js[0].js 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: ObjC.import("AppKit") $.NSPasteboard.generalPasteboard.pasteboardItems.js[0].types.js.map(c => c.js) Link to comment
tomvo Posted February 4, 2023 Author Share Posted February 4, 2023 @vitor thanks for the tips, I ended up with this https://github.com/tomvanoppens/alfredflows/blob/main/Paste to active dir.alfredworkflow Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now