macaliaser - script to create aliases for applications on OSX / MacOS
- generation of aliases MacOS applications for shell use
- black listing og applications for alias generation
# Generate aliases in /Applications directory $ macaliaser -i /Applications # Generate aliases in /Applications directory and Applications directory in users home directory $ macaliaser -i /Applications $HOME/Applications # help message $ macaliaser -h # Serialize the generated aliases to a file in you home directory $ macaliaser -i /Applications > ~/.aliases
This script create aliases from all the applications in the directories you scan.
The recommended usage is to put the aliases in a separate file and use the from you preferred shell.
I have the following line in my
So the script can proces the file with out conflicting with other
settings, apart from the
.bash_profile change, I have added the
following line to my
0 12 * * 1 $HOME/bin/macaliaser -i /Applications/ \ $HOME/Applications/ > $HOME/.aliases
Do note that
cron is not necessarily running under the same shell as the user
so in order to get a proper path set for useful alias suggestions, you might have
to tweak the environment and emulate a user shell session, like so:
0 12 * * 1 . $HOME/.bash_profile; $HOME/bin/macaliaser -i /Applications/ \ $HOME/Applications/ > $HOME/.aliases
This sources the shell (bash in this case) resource file prior to execution. See Stack Overflow
You can enable black listing of applications by adding a file named:
$HOME/.config/macaliaser/blacklist like this example:
/Users/jonasbn/Applications/Chrome Apps.localized/Default \ pjkljhegncpnkpknbcohdijeoejaedia.app
Do note that the spaces are not escaped.
This indexes the directories listed after
--or provided as arguments to
This outputs informative messages to
STDERRso you can filter it from the generated data, which is printed to
This checks whether a file has a name in the format:
Do note that names can contain spaces and this is handled.
If this is true it processes the entry further SEE suggest.
suggest suggest different aliases for your applications, each
suggestion is tested for existance by is_cmd, which relies on File::Which,
so we do not overrule any existing commands (like
The tries are done in the following order:
- lowercase, name without .app extension, example:
- lowercase, name with .app extension, example:
- uppercased first letter with .app extension
- the original name
cmd_exists check whether there already is a command with the suggested alias in path.
This uses File::Which’s
which subroutine, which works like the shell command <which>
create_alias is used to create the actual alias, based on the suggestions from suggest.
Alias are actually just strings in the form of:
alias somealias="open -a /some/path/to/an/app"
- MetaCPAN: File::Which
- MacOS man page: open command
- MacOS man page: bash, contains information on alias command
- jonasbn firstname.lastname@example.org
macaliaser is (C) 2004-2018 Jonas B. Nielsen (jonasbn) email@example.com
macaliaser is free software and is released under the Artistic License 2.0.