Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had a similar thought since I wanted to integrate <code>drush</code> (a command line tool to manage <code>drupal</code> sites) with MAMP and MAMP Pro and make it possible to automate the creation of a virtual host for testing. </p> <p>The information you manually add to MAMP Pro gets stored in the file <code>~/Library/Preferences/de.appsolute.mamppro.plist</code> which is then used to modify/create <code>/etc/hosts</code> and the <code>httpd.conf</code> file based on the template file. Actually the template files are stored in <code>~/Library/Application Support/appsolute/MAMP PRO/templates</code> and the generated files in <code>Library/Application Support/appsolute/MAMP PRO/</code> (check <code>httpd.conf</code> as well as <code>hosts</code> in this folder ).</p> <p>There is no point editing those files anyway since they are generated by MAMP every time you save the manual modifications and restart (well haven't investigated the details of it but I remember that when I tried to manually edit those files I had no hope).</p> <p>What you need to do is to edit the <code>plist</code> file <code>de.appsolute.mamppro.plist</code> directly. Reading and writing to <code>plist</code> files can be achieved using <code>PlistBuddy</code> (<code>/usr/libexec/PlistBuddy</code> see <code>man PlistBuddy</code>).</p> <p>You can extract the information in the <code>plist</code> file using the command:</p> <pre><code>/usr/libexec/PlistBuddy -c Print ~/Library/Preferences/de.appsolute.mamppro.plist </code></pre> <p>A typical (single) record of a virtual host with this command would look like this:</p> <pre><code> Dict { MultiViews = false documentRoot = /home/test/openpublish-2.3 Order = 0 ExecCGI = false serverAliases = Array { } dyndns = Dict { displayName = - } serverName = openpublish-2.3 FollowSymLinks = true AllowOverride = 0 local = true Allow = 0 Includes = true Indexes = false SymLinksifOwnerMatch = false } </code></pre> <p>where <code>documentRoot</code> and <code>serverName</code> are the main values you need for each virtual host. If you want the output to be in the form of an xml plist then add the <code>-x</code> option:</p> <pre><code>/usr/libexec/PlistBuddy -x -c Print ~/Library/Preferences/de.appsolute.mamppro.plist </code></pre> <p>The single record above is one of many in an array which has the following structure:</p> <p>virtualHosts = Array { Dict { ...Virtual Host 1 values... } Dict { ...Virtual Host 2 values... } Dict { ...etc... } }</p> <p>The above commands spit out the whole <code>plist</code> file. Using the man page alone it was a long pain to find out how one can focus on <code>virtualHosts</code> array or say the second <code>Dict</code> (record) in the <code>virtualHosts</code> array. Thanks to <a href="http://prowiki.isc.upenn.edu/wiki/Manipulating_Plists" rel="nofollow">this page on Manipulating Plists</a> I got it (in the following commands I skip the <code>/usr/libexec/</code> part) right: to access the whole <code>virtualHosts</code> array use the command:</p> <pre><code>PlistBuddy -c "Print :virtualHosts" ~/Library/Preferences/de.appsolute.mamppro.plist </code></pre> <p>to print the second record:</p> <pre><code>PlistBuddy -c "Print :virtualHosts:2" ~/Library/Preferences/de.appsolute.mamppro.plist </code></pre> <p>to print the <code>documentRoot</code> of the fifth <code>virtualHosts</code> record:</p> <pre><code>PlistBuddy -c "Print :virtualHosts:5:documentRoot" ~/Library/Preferences/de.appsolute.mamppro.plist </code></pre> <p>According to the <code>man</code> page <code>PlistBuddy -c Add entry type [value]</code> would do the trick for you (i.e. add/write the required record) so your problem can be solved by combining the above info with the man page and the link (the link is useful if you would like to make a script).</p> <p>I have not completed my automated scripts yet (<code>drush</code> code in <code>php</code> or <code>bash</code>script is my preference) but I think the following points will help you:</p> <p>Firs of all if you are doing any tests make sure you make a back-up of <code>de.appsolute.mamppro.plist</code> first or you copy this file and do all the tests on the copy. So in the following I assume you are on a terminal and you have already aliased the command and copied the <code>plist</code> file as follows:</p> <pre><code>$ alias PlistBuddy="/usr/libexec/PlistBuddy" $ cp ~/Library/Preferences/de.appsolute.mamppro.plist safe_to_play.plist </code></pre> <p>To add a new <code>Dict</code> to <code>virtualHosts</code> array:</p> <pre><code>PlistBuddy -c "Add :virtualHosts: dict" safe_to_play.plist </code></pre> <p>to find the index of the new virtual host entry then do something like (<code>bash</code> script assumed):</p> <pre><code>PlistBuddy -c "Print :virtualHosts: dict" safe_to_play.plist | grep documentRoot | wc -l </code></pre> <p>and to add the <code>documentRoot</code> entry for this new record:</p> <pre><code>PlistBuddy -c "Add :virtualHosts:XXX:documentRoot string /home/path" safe_to_play.plist </code></pre> <p>where <code>XXX</code> is the line number output from the previews command (since index of arrays starts with 0).</p> <p>Of course you have to repeat this for all the entries (<code>FollowSymLinks</code>, <code>serverName</code> etc) making sure you respect the structure and type (you have arrays and integers and strings in the single <code>Dict</code> entry). Last but not least MAMP Pro (or at least the servers) must be restarted for the changes in <code>~/Library/Preferences/de.appsolute.mamppro.plist</code> to take effect. Once again do back-up your <code>plist</code> file!!!</p> <p>I hope this helps you produce the script you wanted.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload