I often travel using Finder in the source directories of various project (LaTeX articles, programming stuff) for which the compilation is piloted by a Makefile. I was wondering if there is a simple way (Service menu, Automator whatever) to invoke the corresponding command (make) in the good directory directoly from Finder (right-click something).

I'm running OS X 10.8.

Thanks by advance for your suggestions

  • Not sure about 100% Finder make-ing, but, you could open a Terminal window and type make then drag the Makefile into the Terminal to copy the path to it. – 2rs2ts Jun 11 '13 at 22:05
  • 1
    @2rs2ts, if you go this way, type make -C before dragging the Makefile. – lhf Jun 19 '13 at 11:15
  • @lhf Ah yes, of course. – 2rs2ts Jun 19 '13 at 15:48
  • 1
    Adding to @2rs2ts you do probably want the make in a terminal or from an editor to see the error messages – mmmmmm Jun 19 '13 at 22:17

You could use a function like this:

fmake() {
  cd "$(osascript -e 'tell application "Finder"
      POSIX path of (target of Finder window 1 as alias)
  end tell' 2> /dev/null)"
  make && make install

Or save a function just for the cd command and use history-search-backward to run something like cdf && make && make install.

Or open Automator, choose the Service template, set the input type to no input, and add a Run AppleScript action like this:

    tell application "Finder"
        POSIX path of (target of Finder window 1 as alias)
    end tell
    tell application "Terminal"
        do script "cd " & quoted form of result & " && make && make install"
    end tell

Without the try block Automator would show an error dialog if the script exits with an error.

  • You could also pipe the stdout and std to see errors or at least prompt where the error log is – mmmmmm Jun 19 '13 at 22:18

Admitted, this is a clumsy way but maybe better than nothing:

create a text file named makeit.command and just put one line of text into it:


Then chomod the file 755

chmod 755 makeit.command 

If you want to run a make, drag/copy it to that folder and then double click it.

  • 1
    In that case what is the current directory? I don't think it will be where the Makefile is and so the make will probably fail – mmmmmm Jun 19 '13 at 10:30

I tried adding #!/usr/bin/make -f as the first line of Makefile and making it executable but it does not run in the correct folder. So I've settled for a solution along the lines of the answer by The-Dood.

Open a terminal and go to the folder where you have you project and Makefile, then type this:

cat <<EOF > Makeit
make -C `dirname $_`
echo 'Press enter to continue'
chmod +x Makeit

Now double-clicking Makeit should invoke make on the same folder. You can add any other arguments when calling make or edit Makeit at will.

This solution works but it may not be terribly convenient because you need a copy of Makeit in each folder.


I like Lauri Ranta's AppleScript answer. I was working on such a thing for myself to be able to use the Finder to locate a folder and create a git repository in a directory selected in the Finder.

I can see where you may want to call the make command on a folder as well.

It seems to me that it would be nice to be able to use the Finder's GUI and that you might want to do a lot of things with the selected directory.

Connect to Selected Directory

I think that this Automator Service is more general than issuing any kind of command for a directory inside of the AppleScript and it gets you ready to enter whatever shell command that you want to.

--- edit ---

I'm sorry, my post above didn't answer the original question. Here is a link to an Automator workflow saved as a Service that runs the make command on the directory selected in the Finder:

Run Make

I tried this new service of mine and I didn't like it because sometimes you may want to do the shell command "make" and other times you may want to do the shell command "make && make install", or you may want to build a different target "make fullbuild" or something. That's why I was thinking that a service called "Connect to Selected Directory" would be best.

  • How does this answer the question it appears to be general comments but no exact answer – mmmmmm Jun 19 '13 at 10:32
  • I'm sorry. I meant to provide an exact answer with a link to finished code which when downloaded would install as a Service. – Kaydell Jun 19 '13 at 18:28
  • There is already a preinstalled service (New Terminal at Folder) that does the same thing as your second service. – Lri Jun 23 '13 at 1:51
  • @"Lauri Ranta" Thank you. You sure are knowledgeable. I tried the Service "New Terminal at Folder" it didn't work for me, I think because I set a default directory in my ".bash_profile". For some reason, my Service: "Connect to Selected Directory" works for me, but the Service: "New Terminal at Folder" does open Terminal.app, but it doesn't set the current directory correctly. I get a current directory that is set in my ".bash_profile". – Kaydell Jun 23 '13 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .