Shortcuts Tips: Copy as Embedded YouTube Video

As a follow-on to my Copy as Embedded Tweet’ shortcut that I made last year, I set out to further improve my workflow for preparing posts for 7 Things. That shortcut let me get the proper HTML for embedding a live Tweet right from the Share Sheet. Since I also share a lot of videos in those weekly posts, I wanted a similar solution for embedding videos without having to click through the YouTube website. So, I give you a new shortcut that accomplishes a similar task, but in a different way.

The shortcut in action.

Get the Copy as Embedded YouTube Video’ shortcut → Original Version | Latest Version

This time around, I used very different techniques to build the embed code. Instead of putting together a longer URL by combining one with another, this time I needed to break down the canonical YouTube link for the video.

A screenshot of the shortcut’s actions, labeled in sections.
Can we build it? Yes we can!

1️⃣ To make sure we’re working with a real link and not just text, we use a Get URLs from Input’ action. That pulls the Shortcut Input’ variable, which was either passed into the shortcut or retrieved from the clipboard.

Since we can’t rely on the shared URL to be a link, the first step is to expand the URL out in case it’s a or version.

2️⃣ Once we have the full-length URL, we make the first of two splits using the Split Text’ action. Our goal is to narrow down to just the video’s ID, which always comes directly after the ?v= characters in the URL. After splitting it by those characters, we get the last variable, which includes the ID, using Get Item from List’.

3️⃣ The next split for that variable is by & since additional attributes are after ampersands. We get the first variable from the list this time, which we know must be the video’s ID.

4️⃣ Now that we have the ID, it’s just a matter of filling in that string of characters as a variable into the pre-formatted Text’ action. Since the ID is the only important thing that changes between different embedded HTML for YouTube videos, that’s the only bit we need to change. The text is then copied to the clipboard.

5️⃣ The final two actions serve to confirm that everything has been copied as expected. The Text’ action just lets us format the confirmation message as we please, and the Show Result’ action displays it.

Now the code is ready to be pasted into another text document or website.

Here’s an example:

<iframe width="560" height="315" src="" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

My next challenge is going to be to combine my two embedding shortcuts into one, or running them as functions from a different menu. That, however, will be for another time. So far, using this shortcut throughout the week to prepare links for 7 Things has been working great and saves me time.

Get the Copy as Embedded YouTube Video’ shortcut → Original Version | Latest Version

Let me know if you get some use out of this shortcut, too!

Shortcuts Blogging

❮ Previous post

Apple Makes the Pilot Episode for Its Latest Series ‘The Afterparty’ Available to Watch on YouTube January 27, 2022

Next post ❯

DHH on Apple Talking Out of Both Sides of Their Mouth About Security January 29, 2022