Automate MAMP PRO with AppleScript
MAMP PRO supports AppleScript and JavaScript for Automation (JXA). Both scripting languages give you access to the same set of commands. The examples below use AppleScript; see JavaScript for Automation for the JXA equivalents.
Server control
Section titled “Server control”Get server status
Section titled “Get server status”tell application "MAMP PRO" server status "Apache"end tellReturns one of: stopped, starting, stopping, restarting, running, activatingSystemStart, deactivatingSystemStart, killing, unknown.
Start or stop a single server
Section titled “Start or stop a single server”tell application "MAMP PRO" start server "Apache" start server "MySQL"end telltell application "MAMP PRO" stop server "Apache"end tellReturns the server name on success, or missing value on error. Common reasons for failure: the server is already running, or the name does not match exactly. Use server status to check the current state before calling start server or stop server.
Start or stop all servers
Section titled “Start or stop all servers”tell application "MAMP PRO" start all serversend telltell application "MAMP PRO" stop all serversend tellStart GroupStart servers
Section titled “Start GroupStart servers”Starts only the servers that have Start with GroupStart enabled in MAMP PRO settings.
tell application "MAMP PRO" start groupstart serversend tellManaging sites
Section titled “Managing sites”List sites
Section titled “List sites”tell application "MAMP PRO" list all hostsend tellReturns a list of all site names. Use list active hosts to get only sites that are available when all GroupStart servers are running, or list inactive hosts for the rest.
Add a site
Section titled “Add a site”tell application "MAMP PRO" add host "myproject.local" document root "/Users/me/Sites/myproject"end tellOptional parameters:
| Parameter | Type | Description |
|---|---|---|
site root | text | Path to the site root folder |
ssl | boolean | Enable SSL |
database | text | Name of a new database to create and map to this site |
install WordPress | boolean | Install WordPress automatically |
wpAdminName | text | WordPress admin username |
wpAdminPassword | text | WordPress admin password |
wpDatabaseName | text | WordPress database name |
wpDbUserName | text | WordPress database user |
wpDbPassword | text | WordPress database password |
wpEmailAddress | text | WordPress admin email address |
Add a site with WordPress
Section titled “Add a site with WordPress”tell application "MAMP PRO" add host "myblog.local" ¬ document root "/Users/me/Sites/myblog" ¬ install WordPress true ¬ wpAdminName "admin" ¬ wpAdminPassword "secret" ¬ wpDatabaseName "myblog_db" ¬ wpDbUserName "root" ¬ wpDbPassword "root" ¬ wpEmailAddress "me@example.com"end tellManaging databases
Section titled “Managing databases”List databases
Section titled “List databases”tell application "MAMP PRO" list databasesend tellReturns a list of all MySQL database names. System databases (information_schema, mysql, performance_schema, sys) are omitted.
Add a database
Section titled “Add a database”tell application "MAMP PRO" add database "my_new_database"end tellReturns true if the database was created, false otherwise.
Snapshots
Section titled “Snapshots”Create a snapshot of a site
Section titled “Create a snapshot of a site”tell application "MAMP PRO" create snapshot of host "myproject.local"end tellTo save the snapshot to a specific path:
tell application "MAMP PRO" create snapshot of host "myproject.local" as "/Users/me/Backups/myproject.zip"end tellCreate a snapshot of all sites
Section titled “Create a snapshot of all sites”tell application "MAMP PRO" create snapshot of all hostsend tellJavaScript for Automation (JXA)
Section titled “JavaScript for Automation (JXA)”All commands are available in JXA as well. Run JXA scripts in Script Editor by selecting JavaScript as the language.
const mampPro = Application("MAMP PRO");
// Get server statusmampPro.serverStatus("Apache");
// Start and stop serversmampPro.startServer("Apache");mampPro.stopAllServers();
// List and add sitesconst sites = mampPro.listAllHosts();mampPro.addHost("myproject.local", { documentRoot: "/Users/me/Sites/myproject" });
// Databasesconst dbs = mampPro.listDatabases();mampPro.addDatabase("my_new_database");
// SnapshotsmampPro.createSnapshotOfHost("myproject.local", { as: "/Users/me/Backups/myproject.zip" });mampPro.createSnapshotOfAllHosts();On error, JXA commands return null instead of missing value.