-
Clipboard Manipulation using Keyboard Maestro
Keyboard Maestro has many triggers; these are responsible for executing macros. One such trigger is “The System Clipboard Changes“. I don’t use it often, despite how incredibly useful it is. It does exactly what it says: if a macro uses this trigger, Keyboard Maestro will execute the macro any time the clipboard content changes (when you “copy” something).
Here’s a quick example showing the usefulness.
There is a specific issue I have with Microsoft Outlook webmail within Google Chrome. Our email system leverages urldefense.com to alter all external links in the interface (see below). If I’m clicking a link, that’s fine, but if I want to copy a link’s URL it’s annoying to have to clean up the URL to remove the urldefense cruft.
12BEFORE: https://urldefense.com/v3/__https://someurl.com__;!!LQXXzXo!wt7t_lSnYAFTER: xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxEverything I’ve marked with an “x” is added by urldefense.
The macro is simple. I leverage The System Clipboard Changes trigger to trigger the macro. The macro is inside of a macro group that is only activated for Google Chrome. I use an If Then Else action to determine if the URL is a target for manipulation. Finally, I use a Search and Replace action with some regular expressions to strip off the urldefense cruft.
-
Extracting Image “src” Attributes from an HTML String using PHP
Here are a few ways to build an array of image sources extracted from an HTML string. I’m sure there are other ways, but these seem to be reliable.
1234567$doc = new DOMDocument();@$doc->loadHTML($html);$tags = $doc->getElementsByTagName('img');$image_srcs = array();foreach ($tags as $tag) {$image_srcs[] = $tag->getAttribute('src');}1234567$images = array();preg_match_all('/<img[^>]+>/im', $html, $images);$image_srcs = array();foreach ($images[0] as $image) {preg_match('/src="([^"]*)"/im', $image, $matches);$image_srcs[] = $matches[1];} -
WordPress Plugin: Search Regex
I wanted to quickly mention this plugin as it saved me a bit of time just now. While I worked on this new blog I set the development site up at wordpress.agileadam.com. When I switched the agileadam.com domain over to point to this new WordPress site all of my images stopped working (because the img tags pointed to wordpress.agileadam.com urls; shouldn’t they be relative anyway!? I’ll look into that later).