Jump to content
g8rBryan

Trying to Modify URL in Clipboard

Recommended Posts

I'm relatively new to automation, but I have a few situations where this action would be very useful. I'm just not sure where to start.

 

I want to take my clipboard contents and extract a string from a known point and drop it in the middle of a different known string then either write that to the clipboard or expand it like a snippet.

 

In one instance, I want to pull the document ID for a Google Drive document (I'm uploading via transmit, I don't want to install Google Drive locally) and put it in the middle of a sharing URL.

 

https://drive.google.com/uc?id=1DwOwtpOX-tVb5xd7kws7y1oTZQCJtUtF&export=download
https://drive.google.com/file/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/view?usp=sharing

 

I want to put the 1Dw.... in place of the xxx

 

Thanks in advance, any advice is appreciated!

Share this post


Link to post

If the input is always in that format, one way to do it that might also give you some ideas for general use would be the Argument and Variables UtilityReplace Utility

 

image.png.aca6fb34f7a4011c52e51b5ba2818f1d.png

 

  • The input is keyword with No Argument.
  • The Argument and Variables Utility with {clipboard} as the argument passes the text string from the clipboard to the Replace Utility
  • Replace Utility is set to regex, with an expression that groups the text string received from the previous object into three groups:
    • Group 1) "https://drive.google.com/uc?id="
    • Group 2) whatever is in between Groups 1 and 3 (in this case "1DwOwtpOX-tVb5xd7kws7y1oTZQCJtUtF")
    • Group 3) "&export=download"
    • Then replaces them with "https://drive.google.com/file/d/" + Group 2 ("1DwOwtpOX-tVb5xd7kws7y1oTZQCJtUtF") + "?usp=sharing" as the new string with gets sent as {query} to the next workflow object.
    • From there you can output it back to the clipboard, ready to paste. My screenshot shows Large Type for output just so I could see it and compare to yours.
    • The values in the Replace Utility are Replace regex (https:\/\/drive\.google\.com\/uc\?id=)(.*?)(&export=download) with https://drive.google.com/file/d/$2/view?usp=sharing 
  • If you want to avoid regex, you can use two Replace Utility objects:

 

image.png.bb1b84c96e83787da5a4ac682ea86ab5.png

 

There may be prettier ways to do it, but I thought this might be helpful to see how some of these objects can be strung together.

 

Edited by deanishe
remove screenshot ;)

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...