How to trim URL to root domain?

Done.

1 Like

Hey @JMichaelTX, let me know if it works for you.

If not, we can continue the install-a-perl-module odyssey :grinning:

Oh heck, the odyssey is such fun, let's continue it! :wink:

I get this error:

Can't locate Domain/PublicSuffix.pm in @INC (you may need to install the Domain::PublicSuffix module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /var/folders/_2/7b0tgl916vg3ft82hgl011vm0000gn/T/Keyboard-Maestro-Script-66D1CE2A-91C9-43AA-AD6C-3FB89C73DDBF line 7.
BEGIN failed--compilation aborted at /var/folders/_2/7b0tgl916vg3ft82hgl011vm0000gn/T/Keyboard-Maestro-Script-66D1CE2A-91C9-43AA-AD6C-3FB89C73DDBF line 7.

1 Like

LOL, OK :slight_smile:

First:

Have you installed (with cpanm) the three modules listed in the script (after the “use”)?

Domain::PublicSuffix
Net::Domain::ExpireDate
Date::Calc

If yes, did you get any install errors from cpanm? (“Install failed” or something similar)

No. Sorry, I'm on a different Mac now, and I forgot I needed to do all that stuff.
May I suggest that you add the following to your macro:

  1. Instructions on installing all that stuff, including perl.
  2. At the top of your macro, test for all the modules you need, and report an error if you don't find all of them.

So, if you don't mind, could you please list all of the Terminal install commands for me? Can I run them together, or just one at a time?

Also, what about the path? Why is my path different?

Thanks.

Maybe, someday. But, as you have seen, there is more than one way to install perl :wink:

This information can be found in the Perl script, and perl itself is already testing for the presence of the required modules. (See the error message you have posted above.)

IIRC you succeeded to install perl 5.26 and cpanm on your other Mac two days ago. So I suggest to first read through the posts from two days ago.

To sum it up:

  1. Install perl via Homebrew. Follow the instructions you see in the Terminal during/after the install. (Speaking namely of this one.)

  2. Install cpanm as you have done two days ago.

  3. Create the ENV_PERL5LIB variable in KM with the paths as shown. It is also extremely helpful that you set up your ENV_PATH variable so that it includes the Homebrew install path. These are for example my paths:

    ENV_PATH: /Users/tom/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

    ENV_PERL5LIB: /Users/tom/perl5/lib/perl5:/usr/local/Cellar/perl/5.26.0/lib/perl5/site_perl/5.26.0

    Replace tom with your account name, of course.

  4. Install the modules as required by the script (cpanm <module name>)

Nope. Do as described above and keep an eye on messages in the Terminal.

Also, I would install the modules one by one, because sometimes cpanm throws an error. (Most of the times a dependency problem.)

This has to do how you have configured it during/after the install. (locallib or not, the mentioned HB message).

BTW, since you are on a different Mac now, do you have the ~/.bash_profile and/or the ~/.bashrc on this computer?

What is the best way to check for these and/or display them?

Are these KM Variables, or something I need to set in Terminal?
If in terminal, how do I set them?

Sorry for the basic questions, but remember I'm a shell script novice.
Also, others may have the same questions.

  1. In the Finder go to your Home directory (⇧⌘H)
  2. Show the invisible files with .

No, as said "in KM". See also this KM Wiki article.

  1. Open KM Editor's Preferences (⌘,)

  2. Go to Variables

  3. If the variables are already there, then edit them. If not, then create them by clicking the + button at the bottom of the window.

So, no Terminal needed for that.

No, I do not have either.
How do I create them, and what is their content?

Can I use ~ instead of /users/<MyUserName> ?
~/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

Well, this is weird. I’m on a relatively new Mac myself and I didn’t have to create them. And as far as I remember I never created them.

But a quick search on the Web shows that it is not uncommon that they are missing.

So just create the .bash_profile:

touch ~/.bash_profile

No, this won't work. But you don't need the first one, since probably you don't have a bin directory in your Home folder.

The important part, if you are using Homebrew, is the /usr/local/bin. It should be before the /usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin or whatever you have there.

Separate the paths with a :

To check if KM knows the path execute this action in KM (assuming you have already installed Homebrew on that Mac):

It should give you this:

brew is /usr/local/bin/brew

If you see something like this

/var/folders/wn/28w_v3513m50gcc9qtvg3bfh0000gn/T/Keyboard-Maestro-Script-C3F0A491-02A6-491C-81D6-0A8D6467661B: line 1: type: brew: not found

then your ENV_PATH is not correct.

OK, here is how I translate that into specific commands.
Please review and confirm/correct.

# Is brew installed as part of the macOS?

# Create bash_profile if it does not exit
touch ~/.bash_profile

# INSTALL PERL if not already installed
# use this rather than the perl that comes with macOS
# How can we check to see if it is already installed?
brew install perl

# INSTALL cpan
brew install cpanm

# INSTALL Required Modules
cpanm Domain::PublicSuffix
cpanm Net::Domain::ExpireDate
cpanm Date::Calc

# SET KM VARIABLES
ENV_PATH: /usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin 
ENV_PERL5LIB: /usr/local/Cellar/perl/5.26.0/lib/perl5/site_perl/5.26.0

Nope. Your KM variables are missing exactly the most important parts:

ENV_PATH: /usr/local/bin (before the others, separated by a :). See here.

ENV_PERL5LIB: /Users/jimunderwood/perl5/lib/perl5 (also before the others). See here.

The rest seems correct. But do not blindly execute all in a row. Keep an eye on the messages and follow them! In case of doubt: ask.

OK, here’s my revised instructions:

# Is brew installed as part of the macOS?

# Create bash_profile if it does not exit
touch ~/.bash_profile

# INSTALL PERL if not already installed
# use this rather than the perl that comes with macOS
# How can we check to see if it is already installed?
brew install perl

# INSTALL cpan
brew install cpanm

# INSTALL Required Modules
cpanm Domain::PublicSuffix
cpanm Net::Domain::ExpireDate
cpanm Date::Calc

# SET KM VARIABLES (Rev 1)
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

Questions:

  1. Is brew installed as part of the macOS?
  2. How can we check to see if perl is already installed?

Seems fine. Give it a try :wink:

No. See here how to install it. BTW, I do not want to force you to use Homebrew. There are other package managers, like MacPorts. So feel free to use whichever you want.

perl is installed on every macOS, as well as ruby and python etc. But if you are using a scripting language regularly I wouldn't meddle too much with the ones installed by default, because these are going to be used by other programs and maybe even the system itself. In addition the preinstalled versions are rarely up-to-date.

With

type -a perl

you can see all installed perl versions.