DEV Community

Cover image for Create AppStore Images with one liner
Steven J. Selcuk
Steven J. Selcuk

Posted on

Create AppStore Images with one liner

As an iOS developer, the absolute worst part of releasing an app is creating App Store screenshots.

There are expensive micro-SaaS tools out there. But honestly? They just take your money, and you still end up doing a lot of manual work. I am already paying too much money to Digital Ocean and Google Cloud. I don't need this.

Here is my personal solution. It kills two birds with one stone:

First, we automate our App Store screenshots,
Second, we write UI tests and increase our code coverage.

Here is how you can do it, step-by-step:

Step 1: Take Screenshots with XCTest

Write a simple UI test and use XCTest to take a screenshot. Make sure to keep the attachment so Xcode saves it.

let screenshot = XCUIScreen.main.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
attachment.lifetime = .keepAlways
attachment.name = "AppStore_Home"
add(attachment)

Enter fullscreen mode Exit fullscreen mode

Step 2: Run Your Tests

Just run your UI tests in Xcode (Cmd + U). Xcode will automatically save all these screenshots inside a hidden .xcresult file.

Step 3: Export to Desktop using a Custom CLI Command

Instead of writing a long, messy bash file every time, let's turn this into a simple custom CLI command!

You just need a tool called xcparse (you can install it via Homebrew).

To make it a simple command, open your terminal and add this small function to your ~/.zshrc (or ~/.bash_profile) file:

# Add this to your .zshrc
extract_screens() {
    LATEST_RESULT=$(find ~/Library/Developer/Xcode/DerivedData -name "*.xcresult" -type d -exec stat -f "%m %N" {} + | sort -rn | head -1 | cut -d' ' -f2-)

    mkdir -p ~/Desktop/Screenshots
    xcparse screenshots "$LATEST_RESULT" ~/Desktop/Screenshots

    echo "🚀 Success! Screenshots extracted to your Desktop."
}

Enter fullscreen mode Exit fullscreen mode

Now, restart your terminal. After your tests finish, just type this single command:

$ extract_screens and hit the enter.

Boom! All your App Store screenshots are sitting perfectly on your Desktop. You saved money, saved time, and tested your app. We have a raw screenshot and tot impressed? Totally understandable. The second part will be SVG-based image generation and localization. Click to follow the button. Stay tuned.

How do you currently handle your App Store screenshots? Paying others? Let me know below! 👇


Top comments (0)