bongobong Posted March 17, 2016 Posted March 17, 2016 Hi there, I'm desperate for some help. I save lots of screenshots for work and I need a way of tagging them and/or sending them to specific folders at the time that I take the screenshots. That way they're not in a soup in my images / screenshots folder. I don't want to have to dive into the finder every time. Is there a way of doing this with alfred. If so, can anyone point me in the right direction or help me write a script? James.
FroZen_X Posted March 17, 2016 Posted March 17, 2016 There was a post of something kinda like this a few years ago here: http://www.alfredforum.com/topic/1118-screen-shot-with-aflred/ This is the repo on github: https://github.com/ginfuru/alfred-screen-capture Maybe this is already that what you need.
bongobong Posted March 17, 2016 Author Posted March 17, 2016 Thanks so much! It's not quite what I need. I want to take a screenshot using a hot-key and then up pops a list of folders to send the screenshot; I select one and we're done. Could Alfred take care of this? I think it could. But I don't know how.
deanishe Posted March 18, 2016 Posted March 18, 2016 Yes, but you'll need to do some coding.It appears you need: A Hotkey to trigger your workflow A Script Filter thatTells the system to take a screenshot and save it to a specific location Shows a list of pre-determined folders A script that accepts the path of the folder from the Script Filter and moves the screenshot to it. You can probably grab the screenshot with screencapture.With Alfred-Workflow, showing a list of folders is simple: import os from workflow import Workflow folders = [ '~/Documents/Stuff', '~/Desktop/More Stuff', '~/Dropbox/Screenshots', ] wf = Workflow() for path in folders: p = os.path.expanduser(path) wf.add_item(os.path.basename(path), path, arg=p, valid=True, type='file') wf.send_feedback() If you stick that in folders.py in your workflow, your Script Filter (Language = /bin/bash) might be: set -e screencapture -o $HOME/.temporary-screenshot.png /usr/bin/python folders.py And you'd connect that to a Run Script Action (also /bin/bash): mv $HOME/.temporary-screenshot.png "{query}" JAAE 1
bongobong Posted March 21, 2016 Author Posted March 21, 2016 Superstar !ok. Let me see if I can manage this
bongobong Posted March 21, 2016 Author Posted March 21, 2016 Ok. Learned a lot in the past 10 minutes. I've got the folders.py script in /workflow inside the folder that I get when I click "Show in Finder" on the workflow. I'm just not sure whether this is meant to be the right directory or whether I've done the equivalent of that thing in school where you copy down "1 Banana Town, Orangeville," onto the envelope. I've copied this exactly but should I find out what the finder address of the folder is? set -e screencapture -o $HOME/.temporary-screenshot.png /usr/bin/python folders.py
bongobong Posted March 21, 2016 Author Posted March 21, 2016 Ah. What am I doing wrong? [ERROR: alfred.workflow.input.scriptfilter] Code 2: /usr/bin/python: can't open file 'folders.py': [Errno 2] No such file or directory
deanishe Posted March 21, 2016 Posted March 21, 2016 (edited) You put the script in the wrong directory. It goes in your workflow's root directory, alongside info.plist. If you've installed Alfred-Workflow and have a "workflow" directory, don't put anything in there. That's the Alfred-Workflow library's directory (the first workflow in from workflow import Workflow). Edited March 21, 2016 by deanishe
bongobong Posted March 21, 2016 Author Posted March 21, 2016 Thanks. Sorry to be a pain. Now I'm getting: [ERROR: alfred.workflow.input.scriptfilter] Code 1: File "folders.py", line 5 SyntaxError: Non-ASCII character '\xe2' in file folders.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/for details [ERROR: alfred.workflow.input.scriptfilter] Code 1: File "folders.py", line 5 SyntaxError: Non-ASCII character '\xe2' in file folders.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/for details [ERROR: alfred.workflow.input.scriptfilter] Code 1: File "folders.py", line 5 SyntaxError: Non-ASCII character '\xe2' in file folders.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/for details
bongobong Posted March 21, 2016 Author Posted March 21, 2016 FYI this is what it is: import os from workflow import Workflow folders = [ ‘~/Test 1’, ‘~/Test 2’, ‘~/Test 3’, ] wf = Workflow() for path in folders: p = os.path.expanduser(path) wf.add_item(os.path.basename(path), path, arg=p, valid=True, type='file') wf.send_feedback()
deanishe Posted March 21, 2016 Posted March 21, 2016 (edited) Thanks for posting the code. Obviously, it's impossible to diagnose the error on line 5 without line 5… ‘~/Test 1’, ‘~/Test 2’, ‘~/Test 3’, Those aren't single quotes. It should be: '~/Test 1', '~/Test 2', '~/Test 3', If you're using TextEdit to edit code, stop now and get a proper code editor. TextEdit replaces quotes with "smart" quotes, which will break any source code. TextMate is very good and free.If you need to add valid non-ASCII values (i.e. in one of the folder paths), add this to the top of the script (like in the scripts in the tutorial I linked to earlier): # encoding: utf-8 Edited March 21, 2016 by deanishe
bongobong Posted March 21, 2016 Author Posted March 21, 2016 Thanks for the help! Learning a lot as I go along! And downloading textmate as we speak. So now I've got it sort of working except it doesn't take a screenshot! Have I missed out a step? You said that i could use screenshot so presumably I need to add in a command to do it. "-i Capture screen interactively, by selection or window. The control key will cause the screen shot to go to the clipboard. The space key will toggle between mouse selection and windowselection modes. The escape key will cancel the interactive screen shot."
deanishe Posted March 21, 2016 Posted March 21, 2016 The code I posted earlier to run the workflow takes the screenshot with the screencapture command. I assume you'll want to change the options to the command to take the kind of screenshot you want (window, whole screen etc.). As I wrote in my first post, that code block goes in the Script box in a Script Filter in the workflow. There's a problem (or two) with my code, however. Because it names the screenshot .temporary-screenshot.png, it's (i) invisible in Finder (name starts with a period) and (ii) you can only add one screenshot per folder.This would work better (it adds 1, 2, 3 etc. to the filename): outfile="{query}/Screenshot.png" i=1 while [[ -f "$outfile" ]]; do outfile="{query}/Screenshot $i.png" (($i++)) done mv $HOME/.temporary-screenshot.png "$outfile" Anyway, this is going to take forever to explain in text, so I made the workflow for you.Use that instead, use it as a reference or keep it just in case you can't get your version to work.I made the keyword .screen (with a preceding period), so Alfred doesn't take screenshots every time you enter something that looks a bit like screen.
bongobong Posted March 22, 2016 Author Posted March 22, 2016 Wow. That is incredibly generous Dean. Thank you so much. One final question; how can I make it a select section of screen rather than a screenshot? I'd like to select part of the screen rather than take the whole desktop if possible.
bongobong Posted March 22, 2016 Author Posted March 22, 2016 Ok I've spent 15 minutes looking and I can't find where the workflow is instructing screencapture to capture the picture. I am looking to inserst the command: "-i" it appears but I'm not 100% certain where to put it. "-i Capture screen interactively, by selection or window. The control key will cause the screen shot to go to the clipboard. The space key will toggle between mouse selection and windowselection modes. The escape key will cancel the interactive screen shot."
deanishe Posted March 22, 2016 Posted March 22, 2016 Dude, you even explicitly posted the code yourself. Change screencapture -o $HOME/.temporary-screenshot.png to screencapture -i -o $HOME/.temporary-screenshot.png
bongobong Posted March 22, 2016 Author Posted March 22, 2016 Ah. I didn't realise I needed -i AND -o So now it's doing what I want it to but unfortunately the Alfred bar is displaying directly over the thing that I want to capture. Is there a way to hide it until I need to select the folder?
deanishe Posted March 22, 2016 Posted March 22, 2016 (edited) Done. Download and reinstall the workflow. No idea if you need -o. That just turns off window drop shadows. Edited March 22, 2016 by deanishe
bongobong Posted March 22, 2016 Author Posted March 22, 2016 So I type in screen, hit return, the selector pops up and then I press command-3 and nothing happens. It gives me no option to select the part of the screen I want to capture. Also, is it possible for it to have me select the folder to be put into *after* I take the screenshot. Perhaps that's what's supposed to happen.
bongobong Posted March 22, 2016 Author Posted March 22, 2016 Also, I'd prefer to use cmd-shift-2 rather than typing in screens
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