Safari: primary website functions

###MACRO:   safari: primary website functions

~~~ VER: 1.0    2017-01-08 ~~~

####DOWNLOAD:
safari- primary website functions.kmmacros (29 KB)


###ReleaseNotes

TBD


Here is a macro I use for my browser (can be tweaked for any browser) that gives me one site specific hotkey. I will improve on it further and add more actions to sites but the idea is simple and powerful. Create a hotkey that will do an action for a site that you specify.

Currently, this allows me to search files on github (remove i keystroke, I use it because I have vim in browser and need to enter insert mode). And I also use it to go from reddit subreddits to see their /top of all time. Really awesome thing to do as you find new subreddits. :slight_smile:

Hope this is useful for someone. Also @JMichaelTX, your macro upload macro is superb. :green_heart:
Would be awesome to also have a way to quickly 'update' a macro post. I make some change to a macro, press hotkey and update this very post leaving all my text but just changing the macro uploaded and bumping version number.

One thing I don't understand.

I want to use a regex to filter a variable. I came up with the regex I need but I just don't understand how to use the regex. I just need to apply the regex on a variable. I have something like this right now :

The Search and Replace action is confusing me. I can only search on global variables, that is I can't use my url variable defined earlier. Perhaps this is a wrong action all together for this.

  1. You’re using “Search and Replace Clipboard”. You want "Search and Replace Variable’.

  2. For the Regular Expression, remove the starting and trailing “/” characters. They’re used in JavaScript - don’t use them in a KM action.

1 Like

Thank you Dan.

One thing though. In this action, where does the regex go?

I replace what with what? I am confused. :frowning:

No problem - it's easy to get confused by this.

Change the part in red to one of the "Regular Expression" options.

Thank you Dan.

It's strange. The regex doesn't work. In regex101 it is correct :

But in KM it strips it like this :

The first part of url is gone fully.

If I put it in the second box, it strips it wrongly too. :frowning:

So what is it you’re trying to accomplish?

If I am in a reddit thread (i.e. https://www.reddit.com/r/golang/comments/5mqgwu/go_is_tiobes_programming_language_of_2016/). Pressing a hotkey would bring me to its subreddit.

This regex should in theory do just that. At least it does in regex101 :slight_smile:

Can you give me an example of a specific URL, and exactly what you want it to become?

This link :

would become this :

This :

Would become this :

OK, so get rid of everything from “/comments/” on, right?

Yeah, /comments/ included. :slight_smile:

Thank you.

Either this, which removes the last two "/" values:


Or this, which specifically looks for "/comments/":

1 Like

I said comments too should go though.

This link :

would become this :

Your regex gives me

Can I ask how you figure out the second part?

The ‘and replace with’ part. Because it differs for first and second one. It’s a bit confusing.

I can understand how to come up with a regex in regex101 by playing and testing around. But transferring it to KM is confusing because of this 2nd part of the action.

OK, misunderstood. Sorry.

Either this:

https://regex101.com/r/IHNRcv/2

or this:

https://regex101.com/r/NSyhhx/2

All I did was take the values straight from regex101 and past them into the KM actions. When in regex101, I click in the edit box, and do Cmd+A to make sure it selects everything, then copy.

The only difference is that in regex101, I used the “multiline” (“m”) flag, because I wanted to try two values at once, but I didn’t use this flag in the KM actions because you’re only dealing with one URL.

By the way, I know how frustrating this is to learn, and I give you props for sticking with it! It gets (somewhat) easier… :slight_smile:

1 Like

Thank you so much Dan. This works. :smile_cat:

Yeah, it is a little bit hard at times but so rewarding once you understand it.

Another great thing though is if another person like me will struggle on this same problem, he can just search this forum. That’s what I started to get in habit of doing. Search everything first, then ask. :slight_smile:

1 Like

100% right. Way to go!

:smile:

It gets waaay easier if you spend time learning regex instead of just hacking together things that work.

You have to learn the terminology and the concepts, and you have to practice with problems that are real to you.

More than anything else you have to decide to put in the time and effort.

I speak from experience – I futzed around on the Internet in the mid-90s when there wasn't much to work with, and when I finally bought a book I bought Friedl's “Mastering Regular Expressions” which was a little too advanced for me at the time.

Now I have 4 books dedicated to regex – and several books on Perl (in which regex is extensively used) – and a book on Awk and Sed.

21+ years of regular usage and intermittent study, and I'm still not an expert.  <sigh>

:sunglasses:

-Chris

1 Like