Jump to content

Screenshot to folder / tagger


Recommended Posts

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. 

 

 

 

Link to comment

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. 

Link to comment

Yes, but you'll need to do some coding.

It appears you need:

  • A Hotkey to trigger your workflow
  • A Script Filter that
    • Tells 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}"
Link to comment

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
 
Link to comment

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 by deanishe
Link to comment

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

Link to comment

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()
Link to comment

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 by deanishe
Link to comment

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 window
selection modes. The escape key will cancel the interactive screen shot."

Link to comment

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.

Link to comment

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 window
selection modes. The escape key will cancel the interactive screen shot."

Link to comment

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. 

Link to comment

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...