Install .ttf font using command line - macos

On OS X you can install .ttf font files by double clicking them. This is a hassle when dealing with multiple files. Is there a command to install font files using the Terminal app ?

You could copy the fonts using
cp myfont.ttf /Library/Fonts/
or multiple files
cp fontsFolder/*.ttf /Library/Fonts/

Install fonts with the following command line. Replace BRLNSR with your font and add in more lines if you need more fonts.
cd ~/Library/Fonts && { curl -O 'https://github.com/bloomberg/scatteract/raw/master/fonts/BRLNSR.TTF' ; cd -; }
This code does the following:
cd into the fonts directory
curl downloads the font
pops back to the original directory
This relies on the very nice bloomberg fonts github repo with a bunch of fonts stored - but you could change the curl url to wherever the font you want is located online.
The clever way the cd into a directory, download and pop out again came from user Atle's answer here.

To make the newly copied fonts available to applications requires activating them (for the process, for the user, or for the whole system). This you can do programmatically through various CoreText commands, depending on what you want to do with the font(s). I’m not sure if there’s a way to do this from the command line without turning on auto-activation for everything. See atsutil man pages for (scant) details.

Related

Make link to Application folder

Sublime Text editor has in DMG file link to Applications dir (blue icons with arrow). It has small size.
How to make such link on my own folder? It must work in all Macs.
Open the terminal, use cd to open the folder where you want to create the symbolic link (this is how that kind of link is called, in case you want to research a bit more about it). Example:
cd /Users/MyUser/Desktop/
Note: In case the path has spaces, write it with backslashes before each space, like that:
cd /Users/MyUser/Desktop/My\ Folder/
Then, use that command to create it:
ln -s /Applications/ Applications
It will create a symbolic link which opens the path /Applications/, which means that it will work in any macOS computer.
Reference:
https://apple.stackexchange.com/a/115648

Does usr/local/src on mac not exist?

I am new to computers and using the terminal. Most tutorials I look at for downloading tell me to go to usr/local/src. However, I don't find this on mac. Should I just make a directory called src?
Or is this something specific only to linux users?
If someone could tell me how much difference it makes for this directory to exist or not that would be great. Can I complete my installations in usr/local itself?
Thanks
Using the Finder, you can press Cmd-Shift-G and type /usr to display that folder. The /local folder is there by default, but not its /src subfolder. The Finder, of course, can easily create it for you.
As #cricket_007 mentioned, you need to be certain of what you're doing in this area of the system — that's why OS X doesn't display those folders by default. If you understand the risk and want to see everything in the Finder, you can issue the following Terminal command:
defaults write com.apple.finder AppleShowAllFiles YES
... then type:
killall Finder
and it will look like this. The hidden folders have a slightly faded appearance, but you can navigate into them as desired:
Alternatively (for High Sierra and above)
You may simply use the key combination: " Cmd Shift > " to toggle on and off hidden file display.
It depends what you are doing. If you're messing about just create one in your home directory:
$ cd ~
$ mkdir src
If you building stuff via configure etc., and you want to install it into /usr/local (the default install prefix), then just do this:
$ cd ~/src/packagename
$ ./configure ... options ...
$ make
$ sudo make install

Imagemagick fonts not found in OSX

When trying to add annotations to images in ImageMagick, It failed with the following message:
convert: unable to read font `(null)' # error/annotate.c/RenderFreetype...
How do I make Imagemagick find these fonts?
The solution that worked for me was given by Neville in this post:
Create an imagemagick configuration folder: mkdir ~/.magick
Save this Perl script as /tmp/script.pl
Make the script executable: chmod +x /tmp/script.pl
Run the script locally and redirect the output to the file type.xml in ~/.magick: /tmp/script.pl > ~/.magick/type.xml
This solved the fonts problem, while installing fondu, the imagemagick pkg file and some other tricks didn't.
Great! Now I can annotate some flickr cats with the image size and resolution (I want this for finding the optimal resolution for an app I'm working on).
Adopting Adam Matan's answer, here's how I got this to work with imagemagick 7+ on macOS 10.12+ installed with homebrew. (This also assumes you have perl installed.)
Download the perl script and save it to /usr/local/bin/imagick_type_gen
Make the script executable:
chmod +x /usr/local/bin/imagick_type_gen
Find the font path for imagemagick by running convert -list font | grep Path. This should return where imagemagick is looking for fonts. The Apple path for me was this:
/usr/local/Cellar/imagemagick/7.0.7-22/etc/ImageMagick-7/type-apple.xml
Run imagick_type_gen and direct the output to the path above:
imagick_type_gen > /usr/local/Cellar/imagemagick/7.0.7-22/etc/ImageMagick-7/type-apple.xml
Run convert -list font | less to see the font names imagemagick will use, e.g., some fonts will be labeled as GeorgiaB instead of Georgia Bold. (hit q to quit)
imagemagick should now see the fonts you have installed on the your system.
The easiest way to solve this issue is copying the font you need to a ~/ folder, or anywhere your script is, then give the direct path:
convert -font "~/MyFont.ttc"

OS X - Make returning "Nothing to be done for <filename>"

First of all, I would like to apologize if I'm on the wrong stackexchange network, and secondly, sorry if I'm overlooking something simple.
I was moving files from my old hard drive from an old PC when I came across several password protected ZIP Files. However, since those files were a bit old, I forgot the passwords already. I tried every password I could come up with but I still came up empty. After several google searches, I found this tool/utility for Mac OS X that could help me. So I go to the downloads page and download the Mac OSX utility tool and the source code.
However, I am having problems executing the make command for the file. It says on the downloads page:
If you are using linux or another unix, you need to download the source code, uncompress it and type "make" to compile the utility.
So far, what I've tried is
$make /Users/myname/Downloads/aapr-0.01-source/Makefile
I have also tried the other files in the source folder but nothing worked. After that, I'm pretty much blank. I tried double clicking the aapr file in the utility download for Mac (which is a Unix Executable) and it opens a new terminal window displaying the commands and such. Also, doing $aapr [options] [filename] only shows me -bash: aapr: command not found. I also updated XCodes command line tools.
Sorry if I'm missing out on something very basic, I don't usually use the terminal on the OS X.
Try running
cd /Users/myname/Downloads/aapr-0.01-source
make
A Makefile contains rules for building files from other files but it is based on paths and contents, etc. which depend on your current location. So generally you need to be in the directory of the project for it to work.
Edit (copied from my comment):
To execute a command from a specific location (that isn't in the normal $PATH) you need to specify a path for it. So something like /bin/bash or ./aapr (where ./ means the current directory).

Bookmark Directories In Terminal

Looking for a solution to quickly navigate to long paths in a shell (particularly Max OS X Terminal.app).
Say my path is ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently
Instead of cd ~/This/Is/A/....
I would like to be able to store favorites/bookmark directories so I could do "cd myPath"
Are there any binaries or tools available to do something like this?
I've found the packages 'Apparix' and 'Goto' which together make the stuff dreams are made of for us terminal junkies.
Naturally, I had trouble installing Apparix, but I figured it out in the end.
How To Install Apparix on Mac OS X:
Download the tarball from Apparix's homepage.
Unpack the tarball, cd to the unpacked folder.
Run this command ./configure --prefix=$HOME/local && make && make install.
Run man apparix, scroll down to the heading BASH-style functions, copy everything within that section (delimited with ---) and paste it into ~/.bash_profile.
That's it. You should now have Apparix up and running on OS X (further install info and usage is on Apparix's homepage).
Another solution is to use Bashmarks, which allows you to this
$ cd ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently
$ s shortname # save current path as `shortname`
$ cd /
$ g shortname # cd to ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently
You can use aliases (stick them in your ~/.bash_profile if you want them to always load)
alias cd_bmark1='cd ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently'
Then use by just typing
cd_bmark1
into the console
I know you already found an answer that worked for you, but a couple of more lightweight suggestions that might help others looking for similar things
If your directories are relatively fixed, just long and far away from each other, you can use the CDPATH environment variable to add directories to the search path when typing the "cd" command. If the directory name you try to cd to isn't in the current directory, the other entries in your CD path will also be looked at (and it's also tab complete aware, at least in bash and zsh).
Switching to zsh rather than bash and using the excellent directory stacks abilities. With it, you can maintain a history of directories that you've visited, view the history with the "dh" alias, and easily switch to a directory by using quick shortcuts (ex: cd -3 to switch to the 3rd directory in your history stack).
Why not having a symlink ?
ln -s ~/This/Is/A/Really/Long/Path/That/I/Would/Rather/Not/Type/Frequently bmark
cd bmark
I use to.sh daily to create and navigate bookmarked paths in bash. It supports tag autocompletion and the ability to easily add/remove bookmarks.
https://github.com/Grafluxe/to.sh
Full disclosure, I wrote this tool :)

Resources