macaliaser
macaliaser - script to create aliases for applications on OSX / MacOS
FEATURES
- generation of aliases MacOS applications for shell use
- black listing og applications for alias generation
SYNOPSIS
# 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
DESCRIPTION
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 .bash_profile
source "$HOME/.aliases"
So the script can proces the file with out conflicting with other bash
settings, apart from the .bash_profile
change, I have added the
following line to my crontab
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
Black Listing
You can enable black listing of applications by adding a file named:
blacklist
to $HOME/.config/macaliaser/blacklist
like this example:
/Users/jonasbn/Applications/Chrome Apps.localized/Default \
pjkljhegncpnkpknbcohdijeoejaedia.app
Do note that the spaces are not escaped.
OPTIONS
-
-i (index)
This indexes the directories listed after
--
or provided as arguments to-i
-
-v (verbosity)
This outputs informative messages to
STDERR
so you can filter it from the generated data, which is printed toSTDOUT
FUNCTIONS
is_app
This checks whether a file has a name in the format:
«name».app
Do note that names can contain spaces and this is handled.
If this is true it processes the entry further SEE suggest.
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 mail
).
The tries are done in the following order:
- lowercase, name without .app extension, example:
imovie
- lowercase, name with .app extension, example:
mailapp
- uppercased first letter with .app extension
- the original name
cmd_exist
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
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"
REFERENCES
- MetaCPAN: File::Which
- MacOS man page: open command
- MacOS man page: bash, contains information on alias command
ISSUE REPORTING
AUTHOR
- jonasbn jonasbn@cpan.org
DEVELOPMENT
If you want to contribute to macaliaser
please read the Contribution guidelines
and follow the pull request guidelines.
COPYRIGHT
macaliaser is (C) 2004-2018 Jonas B. Nielsen (jonasbn) jonasbn@cpan.org
LICENSE
macaliaser is free software and is released under the Artistic License 2.0.