I’m not a fan of how Google and other companies track every move you make. However, there are ways to bypass that and still use Google to find what you need. I actually made a Keyboard Maestro shortcut for it, but I’m curious if I can achieve the same result with a PopClip Extension. I’ve tried two different approaches, but I’m unsure what I’m overlooking. The PopClip icon is grayed out in each YAML file, so I can’t click on it. I suppose the first step is to copy the URL and then select the link to activate PopClip.
Here is the first sample using the clipboard:
# PopClip extension to clean the URL of the highlighted text
# Removes everything before "https" and replaces some characters
name: Clean URL
identifier: com.popclip.extensions.cleanurl
version: 1.0
icon: symbol:moon.stars # Apple SF Symbols
actions:
- script: |
#!/bin/bash
# Get the highlighted text
input=$POPCLIP_TEXT
# Remove everything before "https"
output=${input#*https}
# Replace %3A with ":"
output=${output//%3A/:}
# Replace %2F with "/"
output=${output//%2F//}
# Replace %3F with "?"
output=${output//%3F/?}
# Copy the output to the clipboard
echo "$output" | pbcopy
I would greatly appreciate any assistance or guidance you can provide. Thank you in advance!
Hi @macmarty , welcome to the forum. The snippet format is not correct – there’s no such field as “script”. You need to use “shell script” instead (and also, when inputing script inside YAML, specify the interpreter – although I don’t know why it doens’t pick up the shebang at the top, I think it should!). Here’s a lightly edited version that works:
# PopClip extension to clean the URL of the highlighted text
# Removes everything before "https" and replaces some characters
name: Clean URL
identifier: com.popclip.extensions.cleanurl
version: 1.0
icon: symbol:moon.stars # Apple SF Symbols
actions:
- interpreter: bash
shell script: |
# Get the highlighted text
input=$POPCLIP_TEXT
# Remove everything before "https"
output=${input#*https}
# Replace %3A with ":"
output=${output//%3A/:}
# Replace %2F with "/"
output=${output//%2F//}
# Replace %3F with "?"
output=${output//%3F/?}
# Copy the output to the clipboard
echo "$output" | pbcopy
However you can make it a little more comfortable for yourself by using the inverted syntax, so that the whole thing is just a script and you don’t have to worry about the YAML indenting. Here’s how I might format your script:
#!/bin/bash
# # PopClip extension to clean the URL of the highlighted text
# # Removes everything before "https" and replaces some characters
# name: clean url (bash)
# icon: symbol:moon.stars
# after: copy-result
# Remove everything before "https"
output=${POPCLIP_TEXT#*https}
# Replace %3A with ":"
output=${output//%3A/:}
# Replace %2F with "/"
output=${output//%2F//}
# Replace %3F with "?"
output=${output//%3F/?}
# Return the result (will be copied by "copy-result" in config
# and popclip will show "Copied" indicator.)
echo -n $output # note -n flag is needed to suppress echo adding a newline
You can also use PopClip’s internal JavaScript interpreter for a task like this. This is just a preference, but I like JS for simple string manipulation since it doesn’t require calling out to an external process. Here’s my attempt to do the equivalent of your bash script: