Run z-Tree on a Mac:
OSX, MacPorts, and Wine

As the late, great Agatha Christie wrote:

I don’t think necessity is the mother of invention — invention, in my opinion, arises directly from idleness, possibly also from laziness. To save oneself trouble.

As I was working on my MacBook Pro, adjacent to a less attractive (and currently off) PC, I decided to run z-Tree. As purveyors of fine (or bland) economic experiments will know, z-Tree is currently Windows only. As I am too lazy and disinterested in my PC to fire it up and run z-Tree on it, I decided to get it running on my Mac and share with you how easy it actually is.

Preparation

We will be installing Xcode, Command Line Tools, MacPorts, and Wine. So, if you have any of these installed feel free to skip the relevant sections. This tutorial assumes you have a copy of ztree.exe and zleaf.exe. If you do not have these files, you will need to request them via snail-mail using the license contract here or find a friend with a copy.

Step 1: Install Xcode

Download and install Xcode from the App Store [EDIT: If you are on OS X 10.6, follow the instructions for Snow Leopard here]

Step 2: Install Command Line Tools

Command Line Tools

Click “Install” to install the Command Line Tools

  1. Open Xcode
  2. Select the menu option “Xcode -> Preferences …” or press Command+,
  3. Click the “Downloads” tab
  4. Under “Components” click on “Install” on the line for “Command Line Tools”

Step 3: Install MacPorts

Using MacPorts makes it a snap to download and install open-source software on OS X.

  1. Download the MacPorts “pkg” for your OS X version (I tested this while running Mountain Lion) here.
  2. After downloading the MacPorts “pkg”, install MacPorts with the default settings.

Step 4: Install Wine

Wine allows you to run Windows applications within OS X (and Linux) without requiring a copy of Microsoft Window.

  1. Open a terminal: either
    • press Command+Space, type “terminal“, then press Return/Enter,
    • or open Launchpad, and find Terminal in the “Other” group or type “terminal“, then press Return/Enter
  2. Enter the following command:
    sudo port install wine-devel
  3. Enter your password and wait. This will take a while.

Step 5: Run z-Tree

Open a terminal, navigate to the folder containing “z-tree.exe” (i.e., use “cd“) and enter the following command:

wine ztree.exe

This will launch the z-Tree program.

(Optional) Step 6: Setup a shortcut to z-Tree

  1. Open Automator (open Launchpad, and find Automator in the “Other” group or type “automator“, then press Return/Enter)
  2. Select “Application” and click “Choose”
    Select Application

    Select Application

  3. Type “shell” where your cursor is (in the search field that says “Name”).
  4. Double-click the “Run Shell Script” option.
    Select "Run Shell Script"

    Select “Run Shell Script”

  5. Replace “cat” with
    /opt/local/bin/wine /path/to/ztree/ztree.exe

    Be sure to change “/path/to/ztree/” with the actual path to your copy of “ztree.exe”.

  6. Test your application by clicking “Run” (the play button in the top-right corner)
  7. If it works as expected, save your application as “zTree” in the Applications folder.

zTree can now be launched just as you would any other application.

(Optional) Add z-Tree icon to Automator Application

  1. Download a 512×512 z-Tree icon here.
  2. Open “Finder”
  3. Click “Downloads” on the left (assuming that’s where you saved the file) and double-click the file “ztree.hqx”.
  4. Click on the newly created “ztree” icon file.
  5. Press Command+C to copy the icon.
  6. Click “Applications” on the left and find “zTree”.
  7. Control-Click or right-click (or two-finger-click) the “zTree” application
  8. Select “Get Info”
  9. Click on the Automator logo near the top (it will get a blue halo)
    Click the icon near the top-left.

    Click the icon near the top-left.

    and press Command+V to paste the icon.

Congratulations! Now you have zTree running in Mac and it looks native!

(Optional) Step 7: Start zleafs for testing

To run a zleaf for testing purposes enter the following command into a terminal while in the directory containing zleaf.exe:

wine zleaf.exe /name test1

where “test1” is the name you assign to the zleaf. You can then create another zleaf by changing “test1” to “test2” in order to test a 2-subject experiment.

(Optional) Automate zleaf

  1. Open Automator (open Launchpad, and find Automator in the “Other” group or type “automator“, then press Return/Enter)
  2. Select “Application” and click “Choose” as in step 6
  3. Type “ask” where your cursor is (in the search field that says “Name”).
  4. Double-click on “Ask for Text”
  5. For “Question”, type “Type a name for this zleaf.
  6. Leave “Default Answer” blank.
  7. Check “Require an answer”
  8. Change the text “OK” to “Launch zleaf”
  9. Type “shell” where your cursor is (in the search field that says “ask”).
  10. Double-click the “Run Shell Script” option.
  11. Change “to stdin” to “as arguments”
  12. Replace “cat” with
    /opt/local/bin/wine /path/to/ztree/zleaf.exe "$@"

    Be sure to change “/path/to/ztree/” with the actual path to your copy of “zleaf.exe”.

    Your Automator should look like this.

    Your Automator should look like this.

  13. Test your application by clicking “Run” (the play button in the top-right corner)
  14. If it works as expected, save your application as “zLeaf” in the Applications folder.

(Optional) Automate the launching of multiple zleafs

For an application that launches multiple zLeafs at once, replace the above shell command (the section that used to say “cat“) with the following:

for i in $(seq 1 $@) do /opt/local/bin/wine /path/to/ztree/zleaf.exe /name "Player $i" & done

Again, remember to replace “/path/to/ztree/” with the actual path to your copy of “zleaf.exe”. You should also change the prompt in the “Ask for Text” section to something like “How many zLeafs would you like to run?“. I also changed the “Default Answer” to “1“. Save this application as “zLeafs”.

(Optional) Add z-Leaf and z-Leafs icons

To change the icons follow the instructions above and use the following icons:

  • 512×512 z-Leaf icon here.
  • 512×512 z-Leafs icon here.

Concluding Remarks

I hope my efforts will help some of you. Please let me know if you have any questions or problems related to this tutorial in the comments section below.

Comments

  1. Thanks a lot for this great tutorial – this works perfect on Snow Leopard as well!

  2. Jon thank you so much for this post! With a few modifications it worked for my ancient MacBook.

  3. hey its working gr8 on mac but i wanted to know where is the payment file stored or rather the results

    • To my knowledge the payment file does not get stored. You can look at the *.xls and *.sbj files that gets created in your home directory. You can get to the home directory by typing

      cd ~

      in Terminal or in Finder by selecting GO > Go to Folder ... in the menu and entering ~ as the folder to go to.

      Hope this helps!

  4. hey der thanks a ton, i found the result file

  5. hey how do workout the server issue i want to use my mac book as a server

  6. Nice post! I tried using Winebottler to “bottle” the zTree directly, and it went fine! But I’m having a hard time creating different zLeaves to test my treatments. Any thoughts on how to do this, within WineBottler?

    • @Diogo: Unfortunately I haven’t worked with WineBottler. I believe you can create a zleaf.app out of zleaf.exe. You should then be able to create an automator similar to the one in the tutorial.

    • Katherine says:

      Hi Diego, I have also used Winebottler to get zTree running and am having the same problem with creating different zLeaves at a time. Did you figure out how to fix this? I get an error every time I try to create an automator.

  7. Works really well!
    Two questions that would help streamline the process that I can’t seem to figure out.
    1. Is there a way to change the default drop for the data?
    2. Is there a way to close out of the zLeaf program without a Force Quit? Can’t get it to shut down otherwise…

  8. Thanks a lot Jonathan! I got everything to work except for “Automate the launching of multiple zleafs.” I do everything as you say, but Automator says “Workflow completed” after only 2 seconds, and nothing happened. “Automate zleaf” worked fine, but I cannot not run it multiple times in order to get multiple zIeafs. I have Snow Leopard. Any ideas how I could fix this?

    • @Sanne: I’m not sure. I would first check to make sure the shell script reads:

      for i in $(seq 1 $@)
      do
          /opt/local/bin/wine /path/to/ztree/zleaf.exe /name "Player $i" &
      done

      If the zLeaf Automator worked for you, I don’t know why the zLeafs Automator would not. If you post a screenshot of your Automator screen I can help to debug further (make sure not to include any private data).

  9. Hi Jonathan,

    I double checked it, but cannot find the problem. Here is the screen shot:

    Thanks for your help!

    Sanne

  10. nichola raihani says:

    Hi

    This is really helpful thanks for posting it. I have got stuck at level 6 though (I’m really useless at this sort of thing). How do I specify the path to ZTree (my ztree.exe file is in a folder Called “ZTree” that is in “Documents”).
    Sorry for the very easy question! nichola

    • Should be something like “/Users//Documents/ZTree/ztree.exe”.

      Right click on the ztree.exe file and go to “Get Info” to verify this.

      Good luck!

      • Sorry, lost the “”.

        Like this: “/Users/’your_user_name’/Documents/ZTree/ztree.exe”

        • nichola raihani says:

          Thanks for the help 🙂
          I am still encountering errors unfortunately. Specifically, when I enter the code like you said:

          /opt/local/bin/wine “/Users/nichola/Documents/ZTree/z.tree.exe”

          I get an error message saying :

          To test this application within Automator, add the “Get Specified Finder Items” action to the beginning of your workflow. Remove or disable the action before running the workflow outside of Automator.

          I tried doing that but still getting a generic error message as follows:

          The action “Run Shell Script” encountered an error. Check the actionʼs properties and try running the workflow again.

          Any ideas why this might be?? I am using the /bin/bash option for the Shell and it passes input to stdin.

          Do I need to get the specified finder items like Automator says to before I run the script? Or is that unnecessary?

          Thanks for any help you might be able to provide.

          Nichola

        • nichola raihani says:

          By the way, not sure if this makes a difference but I am using Mavericks OS.

  11. nichola raihani says:

    Hey Erich

    A new problem! Did you ever figure out how to get the zleafs to work? I think I have the same issue as you – it works fine in Automator but then doesn’t work from the Applications folder – i.e. I click on the icon and nothing happens. Zleaf (the single one) works fine though.

    thanks! nichola

    • Actually, in order to run multiple Zleafs I use a program that a colleague of mine made. The link is on this page: http://john.jensenius.com/programming.html
      Just download the file under “Launch z-Leafs with GUI (executable).” Move that file to the Zleaf and ZTree directory. Then set up like Jonathan showed for part 6. But you will use /Users/nichola/Documents/ZTree/LaunchZleafsWin.exe instead of /Users/nichola/Documents/ZTree/z.tree.exe

      Then, after you have ZTree open, you can open multiple ZLeaf windows. The first time you run the LaunchZleafsWin.exe you will need to specify where the Zleaf.exe file is.

      Hope that works.

      Best,
      Erich

  12. nichola raihani says:

    Hi again
    Thanks for this advice. I installed the Z-leafs with GUI like you said – seemed to work fine but again when I click it (when zTree is open) nothing happens.

    How do I specify where the Zleaf.exe file is? Maybe that’s the problem? thanks nichola

  13. nichola raihani says:

    I should say – it does ask me how many zleafs want to open but then after i specify a number nothing happens.
    Thanks for your patience.

    • Glad to help.

      On the screen where it asks about the zleafs, there should be a button in the lower left corner: “View or Change All Settings” Click on it. In the box for Z-Leaf path, you should put C:\Users\nichola\Documents\ZTree\zleaf.exe
      That work?

      • nichola raihani says:

        Hello again!

        Do you mean the pop-up screen that says ‘How many zleafs do you want to open’? I literally just get a pop up box asking that question with two options: cancel or launch zleafs. No button in lower left hand corner.

  14. Hi!
    Thanks for this useful post. While following the steps I faced a problem. In Step 4: Install Wine when I type “sudo port install wine-devel” in terminal I get an “Error: Port wine-devel not found”.

    I did not download anything from wine webpage as the tutorial did not suggested it. Also I did not find any “Command Line Tools” in download tab when I installed xCode. I use OS X Mavericks.

    Thanks for your help!
    Homa

    • Kristian says:

      Hi Homa! Did you find solution to your problem? I have the same thing, but I am not sure which wine to download. (BTW: are you friends with Hillary?)

      • Hi Kristian! Sorry for such a late reply, I just got an notification for some other comments and saw yours. I did not find any solutions and I asked my boss for a windows laptop! Which Hillary? Clinton? Haha no I live in Berlin and no Hillary yet 🙂

  15. Cool thank you I used it to run it on wine within ubuntu 12.04 too

  16. always show wine command not found

  17. I’m having problems using Multimedia Box and I’m wondering if it is related to my use of wine. I am inserting the correct link to the file name, but when I run the program no image is showing up. Could this be due to my use of wine to run z-Tree?

  18. Thanks so much for this tutorial. How should I default the language to be English after this setup? I cannot create a shortcut as in the regular setup tutorials. Thanks so much?

  19. J Scriven says:

    Thank you for this! I ended up using the homebrew installer because I kept getting error messages in the terminal install of wine. Combining the general instructions at http://www.davidbaumgold.com/tutorials/wine-mac/#will-it-work and the specifi z-tree info here, I was able to get everything to work. If only there was an easier way to close the z-leafs.

  20. Excuse me for the very simple question, but how can I close the zleaf? I have created a leaf as explained with the automator. However, when I try to close Wine nothing happens for the zleaf and I end up closing it using “Force Quit”. Is there a way to do the alt+f4 in mac to close the zleaf? Thank you so much for your help.

  21. Does running z-tree via Wine on 10.10.4 yield the full functionality? I.e. the same functionality as running z-tree on a Windows machine? If not, does it work better over Parallels? Thanks

  22. Thanks – this worked perfectly! However, do I get exactly the same functionality as when running z-tree with a conventional Windows PC? If not, what issues should I expect?

  23. I have a problem about installing wine. When I try this it started with computing dependencies and then ended with a fail. Could anyone help me about that?

  24. Hi, I have problem when proceeding in Step 5, it says, “could not get window handle”……Could you please help, I am using the EI Capitan. Thank you!

Leave a Reply