Using a Flow in Power Automate to Download EPIC Star Wars Backgrounds

A new Twitter account has popped up, and if you’re a Star Wars fan, you should follow them! Check out @SWfbf. No, it’s not my account, I wish. This account is uploading 4k screen shots from the beautiful scenes in the Star Wars movies and TV shows. Epic right?

I started downloading some manually and then realized I wanted them all, so I had to automate it, of course.

Enter: Power Automate.

High level process of what’s going on:

  • Using a flow, every morning at 6am, it downloads the last post on @SWfbf
  • Flow uploads the image into my OneDrive folder
  • OneDrive syncs to my laptop, and I have that folder set to “Always keep on this device”
  • I configured my backgrounds to point to that folder, and automatically change every 5 minutes.
  • I will also use these as backgrounds in Teams and along side my video backgrounds in Zoom ;)

As always, there were some lessons learned even in this basic flow:

  • Splitting a string on a line return, like \n, is not easily done
  • Twitter sizes its images in the front end, so downloading images came in a little lower size than expected, but there’s a fix

Create the Power Automate Flow

Here’s what it looks like at a high level:

power automate flow downloading star wars images from twitter

Trigger: Recurrence

This is a straight forward trigger. Every morning at 6am this will run. I notice the account posts photos at 8pm, so I’ll download the last nights’ image first thing in the morning.

Action: Twitter Get user timeline

Another easy one, specify SWfbf as the User name.

Initially, set the Maximum results to 100. This will let you back fill up to the last 100 tweets posted.

After it’s first run and downloaded, make sure to set this to 1 or 2. I went with 2, just to make sure I don’t miss a day. It’ll overwrite anyway.

Splitting on a new line

This was more complex than it needs to be. I found the fix on the Power Automate forums (thanks for that!).

The issue is that a string that has a new line in it looks like This is a string\nThis is a new line\nhere's another. If you didn’t see it, the \n indicates a new line. The tweets description looks like:

Note the (2015) [4k... line is on a new line. The text that the flow reads is The Force Awakens\n(2015) [4k... To properly name my images, I just wanted the first line, so let’s split on the line break.

We can’t split on \n. No idea why, my guess is that the \n is a reserved character and Power Automate is not sure what to do with it. Fortunately we have a workaround.

Action: Initialize Variable NewLineHack

This is a two part fix. The first one, just add an action to initialize a new variable. Set the type to String. Set the value to

Line 1  
Line 2

That would like like

Line 1 \nLine 2

See the spaces? Type in Line 1, then 2 spaces, hit enter, and type in Line 2.

The second part is what gets the new line value.

Action: Compose NewLineHack

For the Inputs of this action, specify:

take(first(skip(split(Variables('NewLineHack'),'  '),1)),1)

What is this doing? Start in the middle:

Variables('NewLineHack') is the variable set in the previous action.

split(Variables('NewLineHack'),'  ') splits the value of the previous on the two spaces. A split returns an array of values.

skip(split(Variables('NewLineHack'),'  '),1) skips the first item in the array

first(skip(split(Variables('NewLineHack'),'  '),1)) takes the first item in the array (remember we skipped the first one, so now we’re on the second one, which is the new line value)

take(...) then takes that value.

Easy, right?

Action: Apply to Each tweet body

Add a new Apply to each action, and for the value to use, specify the Body from the Get user timeline action. This will allow us to loop through all the tweets on the @SWfbf timeline.

Action: Apply to Each Photo URL

Add a new Apply to each in the above Apply to each. For the value, use the Expression tab in the dynamic content window, and type in: items('Apply_to_each')['MediaUrls']. This will take the MediaUrls field from the item the Apply to each is looping on.

Action: OneDrive for Business Upload file from URL

Now let’s upload!

For Source URL, select Current Item from the picker list, making sure to pick the current item from the 2nd apply to each. Then add ?format=jpg&name=4096x4096 right after it. This will get a higher-res version of that image.

Destination path, specify where you want this to download to. I have a zoom_backgrounds folder that I use for my video backgrounds. I now have a subfolder there for the starwars images.

To name the file, I only wanted the first part of the tweet text, that first line, so let’s split the text on the new line value. Use the expression and type in

split(items('Apply_to_each')['TweetText'], outputs('NewLineHack Compose'))[0]

Apply_to_each is from the first Apply to each one, the one looping the body.

Then I append the tweet id, since the naming is not unique, it’s just the name of the movie or episode it comes from. Finally, add .jpeg so it saves as an image.

I also set it to Overwrite, so I can grab the last 2 every day, just in case I miss one.

All in, it looks like:

Run your flow!

With any luck, it’ll run and you’ll get your images. Pretty easy, right?

Don’t forget to update your twitter action to a maximum results of 2, no need to download 100 every morning.

Now I have all the images from the account, and each morning I’ll get the latest and greatest!

What’s next?

Since you’re in flow, you can do so much more!

  • Upload the image to a file share for your team to share
  • Post it to Teams or Slack
  • Email to your friends
  • Retweet the tweet on your account
  • and more!

Leave a Reply

Powered by

Up ↑

%d bloggers like this: