Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have the same wish. I want to be able to save screenshots from a few screens in my app without all the manual work. I'm not there yet, but I have started.</p> <p>The idea is to tail /var/log/system.log, where the output from the NSLog statements go. I pipe the output to a python program. The python program reads all the lines from stdin and when the line matches a specific pattern, it calls screencapture. </p> <pre><code>NSLog(@"screenshot mainmenu.png"); </code></pre> <p>That will cause a screenshot named "XX. mainmenu YY.png" to be created every time it is called. XX is the number of the screenshot since the program started. YY is the number of the "mainmenu" screenshot. </p> <p>I have even added some unnecessary features:</p> <pre><code>NSLog(@"screenshot -once mainmenu.png"); </code></pre> <p>This will only save "XX. mainmenu.png" once. </p> <pre><code>NSLog(@"screenshot -T 4 mainmenu.png"); </code></pre> <p>This will make the screenshot after a delay of 4 seconds. </p> <p>After running an app with the right logging, screenshots with the following names could have been created: </p> <pre><code>00. SplashScreen.png 01. MainMenu 01.png 03. StartLevel 01.png 04. GameOver 01.png 05. MainMenu 02.png </code></pre> <p>Give it a try:</p> <ol> <li><p>Add some NSLog statements to your code</p></li> <li><p>$ tail -f -n0 /var/log/system.log | ./grab.py </p></li> <li><p>Start your iPhone app in the Simulator</p></li> <li><p>Play around with your app</p></li> <li><p>Have a look at the screenshots showing up where you started the grab.py program</p></li> </ol> <p>grab.py:</p> <pre><code>#!/usr/bin/python import re import os from collections import defaultdict def screenshot(filename, select_window=False, delay_s=0): flags = [] if select_window: flags.append('-w') if delay_s: flags.append('-T %d' % delay_s) command_line = 'screencapture %s "%s"' % (' '.join(flags), filename) #print command_line os.system(command_line) def handle_line(line, count=defaultdict(int)): params = parse_line(line) if params: filebase, fileextension, once, delay_s = params if once and count[filebase] == 1: print 'Skipping taking %s screenshot, already done once' % filebase else: count[filebase] += 1 number = count[filebase] count[None] += 1 global_count = count[None] file_count_string = (' %02d' % number) if not once else '' filename = '%02d. %s%s.%s' % (global_count, filebase, file_count_string, fileextension) print 'Taking screenshot: %s%s' % (filename, '' if delay_s == 0 else (' in %d seconds' % delay_s)) screenshot(filename, select_window=False, delay_s=delay_s) def parse_line(line): expression = r'.*screenshot\s*(?P&lt;once&gt;-once)?\s*(-delay\s*(?P&lt;delay_s&gt;\d+))?\s*(?P&lt;filebase&gt;\w+)?.?(?P&lt;fileextension&gt;\w+)?' m = re.match(expression, line) if m: params = m.groupdict() #print params filebase = params['filebase'] or 'screenshot' fileextension = params['fileextension'] or 'png' once = params['once'] is not None delay_s = int(params['delay_s'] or 0) return filebase, fileextension, once, delay_s else: #print 'Ignore: %s' % line return None def main(): try: while True: handle_line(raw_input()) except (EOFError, KeyboardInterrupt): pass if __name__ == '__main__': main() </code></pre> <p>Issues with this version:</p> <p>If you want to take a screenshot of only the iPhone Simulator window, you have to click the iPhone Simulator window for every screenshot. screencapture refuses to capture single windows unless you are willing to interact with it, a strange design decision for a command line tool. </p> <p><strong>Update:</strong> Now iPhone simulator cropper (at <a href="http://www.curioustimes.de/iphonesimulatorcropper/index.html" rel="noreferrer">http://www.curioustimes.de/iphonesimulatorcropper/index.html</a>) works from command line. So instead of using the built in screencapture, download and use it instead. So now the process is completely automatic. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload