Addon/Toolbox Post Install Hooks
Show older comments
I was wondering if there is any form of post install hooks for add-ons and downloads. Depending on the environment an installation happens in there may be a need to apply some post install configuration. I couldn't find anything in the docs or Package Toolbox dialog. Was hoping somebody else has found a solution that I may not have found in the docs.
The ideal solution would be one that works in interactive (GUI, Command Window) and non interactive environments (CI, deployments, scripts etc).
Answers (1)
Jack
on 29 Mar 2023
Yes, there is a way to run post-installation code after installing a MATLAB add-on or toolbox using the MATLAB Add-On Manager.
You can create a file named "startup.m" in your MATLAB user folder or project folder. MATLAB automatically runs this file when it starts up, and you can use it to run any custom code you want.
To run post-installation code after installing an add-on or toolbox, you can add the code to the "startup.m" file, and MATLAB will run it the next time it starts up. You can use conditional statements to make sure that the post-installation code only runs if the add-on or toolbox has been installed.
For example, you can use the "isToolboxInstalled" function to check if a specific toolbox is installed, and then run the post-installation code if it is. Here's an example:
if isToolboxInstalled('myToolbox')
% Run post-installation code here
end
Similarly, you can use the "isAddonEnabled" function to check if a specific add-on is enabled, and then run the post-installation code if it is. Here's an example:
if isAddonEnabled('myAddon')
% Run post-installation code here
end
You can also use other functions and commands in the "startup.m" file to configure your MATLAB environment or load specific settings and preferences.
Note that the "startup.m" file is run every time MATLAB starts up, so make sure your code is efficient and doesn't cause unnecessary delays or errors.
5 Comments
Alexander
on 29 Mar 2023
Jack
on 30 Mar 2023
Ah, I see. In that case, you can add a custom install script to your MATLAB toolbox/add-on to perform any necessary post-installation steps. Here are the steps to do so:
- Create a script file that contains the post-installation steps you want to perform. Make sure the script is compatible with the version of MATLAB you are targeting.
- In the root directory of your MATLAB toolbox/add-on, create a folder called "resources" if it doesn't exist already.
- Inside the "resources" folder, create a new folder called "scripts".
- Save your post-installation script file in the "scripts" folder.
- Rename your script file to "postInstall.m". This is the standard name for a post-installation script in MATLAB.
- In your toolbox/add-on installation script, add the following command to run the post-installation script:
install.addon({'toolbox_name'},'postinstall','true');
Replace "toolbox_name" with the name of your toolbox/add-on. This command will trigger the post-installation script after the toolbox/add-on is installed.
- Make sure your toolbox/add-on and the post-installation script have appropriate permissions to run on the target machine.
That should do it! When a user installs your toolbox/add-on, MATLAB will automatically run the post-installation script after installation is complete. You can use this script to perform any necessary setup, configuration, or other tasks that your toolbox/add-on requires.
Alexander
on 30 Mar 2023
Jack
on 31 Mar 2023
I apologize for the confusion. The install function I mentioned is actually part of the MATLAB Add-On Explorer and is used to install add-ons from the MATLAB Central File Exchange or other repositories.
To install support packages in MATLAB, you can use the "Add-Ons" menu in the MATLAB desktop interface:
- Click on the "Add-Ons" dropdown menu in the MATLAB desktop interface.
- Select "Get Add-Ons" to open the Add-On Explorer.
- In the "Available Add-Ons" tab, search for the support package you want to install.
- Click on the support package to open its details page.
- Click the "Install" button to download and install the support package.
Alternatively, you can use the supportPackageInstaller function to install support packages programmatically from the command line. Here's an example code snippet:
supportPackageInstaller % open the support package installer GUI
This code should open the support package installer, where you can select and install the support package you need.
I hope this helps! Let me know if you have any further questions.
Alexander
on 31 Mar 2023
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!