How to trim URL to root domain?

Looks great :slight_smile:
Install cpanm now, please.

Success:

/usr/local/Cellar/cpanminus/1.7043: 6 files, 381.6KB, built in 3 seconds

Now install CPAN modules?
One at a time, or all 3 at once?

As a sidenote: After doing certain things (for example setting env variables or changing the contents of .bash_profile or .bashrc) always start a new Terminal session!

1 Like

Well, as already discussed, I would install them one by one. But if you insist, try to install all at once :wink:

Don't worry, this will not take much time, either way.

I figured you'd say that, so that is what I did.
All successful:

Successfully installed Domain-PublicSuffix-0.14
5 distributions installed

Successfully installed Net-Domain-ExpireDate-1.19
22 distributions installed

Successfully installed Date-Calc-6.4
5 distributions installed

Now all I need to do is set the KM ENV variables.

1 Like

Great! :slight_smile:

Maybe adding the procedure to the KM Wiki?

Just to be sure this time: Check if the newly installed modules really are in /Users/jimunderwood/perl5/lib/perl5

Looks like to me:

Yeah! This is insanely great :slight_smile:

The script should run now.

Yep. Your macro works like a charm: :smile:

Whew! What a workout! :wink:

Thanks for all your help and patience, Tom. Much appreciated.

Here's my final instructions:

### 1. Install Homebrew IF not installed ###
# To See if Homebrew is installed:
type brew

# IF NOT installed, will return:
# -bash: type: brew: not found

# TO INSTALL Brew: #
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# IF installation is successful, you will see:
# ==> Installation successful!

### 2. Create bash_profile if it does not exist ###
touch ~/.bash_profile

# this creates an EMPTY file???

### 3. INSTALL PERL if not already installed ###
# use this rather than the perl that comes with macOS
# To See All Installed Versions of perl:
type -a perl

# Returns ONLY this IF you need to install latest ver:
# perl is /usr/bin/perl

# Install to get perl 5.26+ (in addition to macOS ver)
brew install perl

# If successful, you will see something like this:
# /usr/local/Cellar/perl/5.26.0: 2,389 files, 57.3MB

#By default non-brewed cpan modules are installed to the Cellar. If you wish
# for your modules to persist across updates we recommend using `local::lib`.

# You can set that up like this:
PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib
# Answer yes to auto-configure question.

# Then execute this:
echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >> ~/.bash_profile
  
### 4. INSTALL cpanm (aka cpanminus) ###
# It is an alternate (but well established) CPAN package manager. 
# It is less difficult to handle
brew install cpanm

### 5. INSTALL Required Modules ###
# Install one at a time.
cpanm Domain::PublicSuffix
cpanm Net::Domain::ExpireDate
cpanm Date::Calc

### 6. SET KM VARIABLES (Rev 1) ###
# Do this in KM Editor App, Preferences > Variables
ENV_PATH: /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin 
ENV_PERL5LIB: /Users/<MacUserName>/perl5/lib/perl5:/usr/local/Cellar/perl/5.26.0/lib/perl5/site_perl/5.26.0

1 Like

What do think about my idea to wikify this? As “Standalone perl installation via Homebrew” or something like that.

Please note that all we have done here is not necessary to run the occasional Perl one-liner in the command line, like for example in this macro. The OS’ default perl is good enough for that.

But, if you have a script that requires additional (non-core) modules, IMO the independent install, as we have done it here, is the better way.

Heck, this thread now has more replies than views :grin:

If nothing else, you guys have demonstrated why native Keyboard Maestro actions are more useful to most people :wink:

4 Likes

Yep. And a great thing with KM is that you are not limited to native KM actions :wink:

2 Likes

I slightly polished the script output. Go here.

Roger that!

So, Peter, does that mean you will be adding a KM Action to get the root domain? :wink:

As you have seen, it is very hard to do. There are many StackOverflow posts trying to figure this out, and I haven't seen any that really does the job. @Tom's solution is the best, most complete I have seen.

I think that might be a good idea. It is a very complicated process for bash and perl novices, like me. Would you mind starting with my install instructions, and add to it as you see fit, since you're the perl expert?

Could this be automated?

Yeah, fortunately there are perl modules for almost everything :wink:

BTW, the script fails on some TLDs, namely 'de'. But, as far as I have seen, this is because the response of the Whois server just doesn't contain the creation date for these TLDs.

OK, I will try to write it up (not today). But you'll have to correct my English before putting it on the Wiki.

Even if it's possible I wouldn't do it. It's always beneficial if the user knows/learns what he's doing, and this is better achieved if he is executing the steps himself, guided by instructions. IMO.

Well, this is a three year old thread, but since this topic was so extensively, exhaustively, discussed, I thought I'd post a link to my latest solution, for all to review, test, and comment on.

And, to @peternlewis' point, it is an all native KM solution, with no scripting.

MACRO: Extract Domain from URL [Example]