macOS Tricks & Hacks: Automatic Script that Links Apps from Home Folder to Root Applications Folder
For a couple of years, I have noticed that a few of my applications have been installed into an Applications folder in my home folder (~/Applications). While I am unsure why this is the case, it has caused me headaches as I am used to navigating directly to the main Applications folder to find all of my apps (/Applications). Furthermore and annoyingly, some of the apps were buried within folders! Using launchd and python, I made a script that will add soft links for each app buried within the home Applications folder to the root Applications folder automatically.
Since I wanted to link the Applications from sub directories, I used the Path module from pathlib as it contains methods for finding files recursively:
# get the files listOfHomeApps = Path(homeAppsPath).rglob('*.app') listOfMainApps = Path(mainAppsPath).glob('*.app')
Once the files paths are obtained a soft link is created using the "ln -s" unix command. This will place all apps in the root Applications folder without hiding them in any sub-folders:
# make soft link source = str(app.parent / app.name) destination = str(Path(mainAppsPath) / app.name) system('ln -s "' + source + '" "' + destination + '"')
If any apps were deleted from the home applications folder, the script will also remove them using the unix "rm -f" command:
# remove dead soft links from /Applications # <...snipped code...> if sourceExist: print(TermColors.white + '\t"' + str(linkSource) + '" is alive!') else: print(TermColors.red + '\t"' + str(linkSource) + '" is dead...deleting...') system('rm -f "' + str(Path(mainAppsPath) / app.name) + '"')
Whenever a change is detected in ~/Applications, the script is then run automatically using a launchd user agent. I prefer to use an app called LaunchControl to manage my daemons/agents as I have too many systemctl commands floating around in my head. However, one could modify the plist included on the Github project to match their system and activate it using launchctl.
If you find this useful, the code along with installation instructions are available for download from my Github page. Enjoy!