Forum Archive

Controlling ScreenShots

reefboy1

Is there a way to control screenshots through pythonista?

dgelessus

No, there isn't. Screenshots are an iOS feature that isn't available to apps. The only way you can take screenshots is manually by holding the home button and pressing the lock button.

peterh86

The iOS app iCab mobile lets you make a screenshot from a menu item, so this is possible from within an app.

omz

...with one exception: It's possible to create screenshots of your own UI:

import ui

def screenshot_action(sender):
    v = sender.superview
    with ui.ImageContext(v.width, v.height) as c:
        v.draw_snapshot()
        c.get_image().show()

v = ui.load_view()
v.present('sheet')

(To use this, create a script with UI, add a button or something like that, and set its action to screenshot_action. The result will be shown in the console, from where you could save it to your photos etc. If you run this on an iPhone, you'll need to close the UI to see it. And yes, I know that this method is not documented... Sorry about that. It's probably not what the OP was asking about anyway, but could still be useful sometimes.)

reefboy1

Ok, thanks. I was thinking of making a screen recorder

reefboy1

@omz I tried your script, but it shows a blank sheet. I close it and it shows the co sole view

omz

Have you actually added anything in the UI editor?

reefboy1

... no

reefboy1

@omz What would I add

0942v8653

reefboy1: what do you want to take screenshots of?

reefboy1

@0942v8653 anything for now

reefboy1

Any suggestions?

dalacv

The workflow app lets you delete screenshots

reefboy1

@dalacv I'm not trying to delete them, I'm trying to Make them. I also would like to use pythonista built in functions, not workflows

omz

Step by step:

  1. Create a new "Script with UI"
  2. In the script part, paste the code above
  3. In the UI part, add some elements (e.g. an ImageView etc.)
  4. Add a button to the UI, open the inspector ("i" button) and set its action attribute to screenshot_action.
  5. Run the script, tap the button you added, the screenshot should appear in the console

Note that this will only make a screenshot of the UI you created yourself. As I said, it's not terribly useful, not what you actually wanted, and you can't make a screenshot of the entire app, your homescreen or whatever else this way...

reefboy1

@omz thank you so much. I love your apps.

reefboy1

Ok my last question is: When I hit the button is it possible to make the devise keep taking screenshots until I click it again?

ccc

Clicking the button saves three screenshots to the local directory.

This script builds its UI at runtime so it requires no .pyui file.

https://github.com/cclauss/Pythonista_ui/blob/master/ScreenshotView.py

reefboy1

Ok cool, thanks

reefboy1

@ccc when I run your script nothing happens, it just shows the console screen

reefboy1

When I click the button is it possible to take the screenshot 3 times in 1 click???

ccc

Use the Pythonista file picker to view the image files: Screenshot_[timestamp].png. Three are created for every click the button so you probably have a pile of them by now. I updated the gist code to print out the filenames as they are created.