Screenshots in Mac OS X

P

Pratik Mehta

Hi Guys,

Good Morning!
How are you all doing?

I am in need of your help.

I am stuck in a problem.

I want to write my own Screenshot Taking program in Python for Mac OS X.

Example : Whenever Command + Shift + 3 is pressed ==> whatever is thereon the screen, should be grabbed / captured, and should be stored on my local with my own desired path, and name should automatically given as SnapshotX.. as in Snapshot1, Snapshot2, etc...

The same goes with Command + Shift + 4 ==> the only difference is that,it allows you to select a particular area to be captured / grabbed.

Command + Shift + 5 ==> This one is a little bit tricky which I am looking for. This shortcut doesn't exist. I want to create one of my own, whereit would grab the entire webpage's screenshot which I am currently workingon, and store the name as the webpage's link.


Thanks in advance for your kind help and time.


Thanks & Regards,
Pratts
 
C

Chris Angelico

Command + Shift + 5 ==> This one is a little bit tricky which I am looking for. This shortcut doesn't exist. I want to create one of my own, where it would grab the entire webpage's screenshot which I am currently working on, and store the name as the webpage's link.

Sounds like a difficult thing to write from scratch. Can you find
something off-the-shelf that takes a snapshot of your current window,
and then maybe add some interaction with the web browser? Otherwise,
you're poking around with screenshotting directly, which is very much
a solved problem.

Also, please read this before you reply:

https://wiki.python.org/moin/GoogleGroupsPython

ChrisA
 
N

Ned Deily

I want to write my own Screenshot Taking program in Python for Mac OS X.

Example : Whenever Command + Shift + 3 is pressed ==> whatever is there on
the screen, should be grabbed / captured, and should be stored on my local
with my own desired path, and name should automatically given as SnapshotX..
as in Snapshot1, Snapshot2, etc...

The same goes with Command + Shift + 4 ==> the only difference is that, it
allows you to select a particular area to be captured / grabbed.

Command + Shift + 5 ==> This one is a little bit tricky which I am looking
for. This shortcut doesn't exist. I want to create one of my own, where it
would grab the entire webpage's screenshot which I am currently working on,
and store the name as the webpage's link.

I'm not sure how much what you want to do differs from what OS X already
provides out of the box but perhaps this reference can give you some ideas:

http://guides.macrumors.com/Taking_Screenshots_in_Mac_OS_X
 
P

Pratik Mehta

Hey Ned,

Thanks for reverting.

I am looking for the similar functionality.

Thanks for sharing that link.

Could you pls help me out with the Python Code?


Thanks. :)
 
K

Kevin Walzer

import os
os.system('screencapture', 'foo.png')
....and see 'man screencapture' for options.

I leave setting up a Tkinter GUI with proper key bindings as an exercise
for the reader.
 
P

Pratik Mehta

Hey John,

I want to code my own Snapshot taking program using Python.

Hence, had posted this question...
 
P

Pratik Mehta

Hey Kevin,

Thanks for reverting.

I know about the "screencapture" function and the parameters available.

But, how would I take the user input, as in, that is just command-line, as soon as I execute the program, it will take whatever kind of parameter is passed under screencapture.

I want that, in the same program, if the user presses Shift+Command+3, whole screenshot should be taken.

When, Shift + Command + 4 is pressed, a particular frame should be displayed to select the area / region.

Also, I want to create my own command : Shift + Command + 5 ==> this isspecially for web browser, whenever I press this key on any of the web-page, the whole web page should be grabbed along with its snapshot, and snapshot's filename should be web-page's url which I am currently on.

Also, this process should be executing at the backend, so that, whenever these keys are pressed, it overrides the system's functionality and uses mine..
 
P

Pratik Mehta

Hey Mark,

Thanks for reverting.

I had tried coding it using os.system("screencapture -s /filepath") // for selecting a particular region..


I have replied to Kevin's comment, that's exactly what I am looking for. :)


Thanks ...
 
K

Kevin Walzer

Hey Kevin,

Thanks for reverting.

I know about the "screencapture" function and the parameters available.

But, how would I take the user input, as in, that is just command-line, as soon as I execute the program, it will take whatever kind of parameter is passed under screencapture.

I want that, in the same program, if the user presses Shift+Command+3, whole screenshot should be taken.

When, Shift + Command + 4 is pressed, a particular frame should be displayed to select the area / region.

Also, I want to create my own command : Shift + Command + 5 ==> this is specially for web browser, whenever I press this key on any of the web-page, the whole web page should be grabbed along with its snapshot, and snapshot's filename should be web-page's url which I am currently on.

Also, this process should be executing at the backend, so that, whenever these keys are pressed, it overrides the system's functionality and uses mine.

There are no simple answers to these questions.

With Tkinter, it's possible to code a basic UI and bind combinations of
specific keys to trigger specific callbacks, which can fire specific
sequences of arguments to the screencapture CLI tool. That's the quick
and dirty way. I'm not going to write this code for you. Look at
TkDocs.com and effbot's site for an introduction to Tkinter.

If you are not looking for a GUI app to do this, but some sort of
system-level daemon, that requires a lower level of coding. You'll need
to look at such system frameworks as CoreGraphics and Cocoa to find the
API's you need. PyObjC (Python binding to Cocoa) can probably be helpful
here. Frankly, I'm not sure Python is the best tool here, but if you go
this route, you want a Python API that hews as closely to the
system-level calls as possible, and PyObjC will likely be your best path
here.

--Kevin
 
M

Mark Lawrence

Hey Mark,

Thanks for reverting.

I had tried coding it using os.system("screencapture -s /filepath") // for selecting a particular region..


I have replied to Kevin's comment, that's exactly what I am looking for. :)


Thanks ...

Assuming that you're talking to me, no problem.

Do you mean "replying" and not "reverting", as I observe that you've
used this elsewhere?
 
M

Metallicow

Well, I'm not going to post my whole module as I get little testing on mac, but I will let you in on a little secret:

Use a GUI, such as wxPython or QT or other, then create a basic fullscreen frame that is invisible and copy its DC to the clipboard. Not exactly a hack(might be edgy), but it works. Writing the gui/logic code will be up to you.

here is a basic wx example

f = wxFrame(None, -1)
f.Show(True)
f.SetTransparent(0)
# Bind your hotkeys to capture the screen.

Also, not sure ATM... but I recall someone wrote a cross platform screenshot implementation IIRC that replaces PIL's ImageGrab module, I think it is pyscreenshot or something similar. You might want to look into that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top