G++ Automator Service

Discussion in 'Mac Programming' started by Moles, Sep 17, 2009.

  1. Moles macrumors newbie

    Joined:
    Jul 9, 2009
    Location:
    Olathe
    #1
    So I am grading papers written for linux in c++. I want to figure out a cool way to compile the programs (.cpp files) from the finder. I was thinking there has to be a way to use Automator to control click the .cpp file and create an object always named test. There probably won't be much linking right now, just standard libs. I just figured that I am spending a lot of time using terminal and figured someone either knows how to do the g++ <filename> -o test command with a service and might be able to help me. I have never used Automator yet so any help is appreciated.

    Thanks in advance.
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    This seems like a good time for make. Are the source files always the same name? Otherwise, it should be easy to make a shell script:
    Code:
    g++ -o test $1
    ./test
    
    should work to build and run, just pass the name of the source file to the script. I don't know that automator is going to do too much for you.

    -Lee
     
  3. Moles thread starter macrumors newbie

    Joined:
    Jul 9, 2009
    Location:
    Olathe
    #3
    The reason I want Automator, is so I can use the context menu services to run the compile operation. I don't have problems running it in terminal. The structure the Professor sends me is a folder for each student, and in that student directory is the source file. I was just hoping someone had run into something like this and made a service to run the essentially shell script.
     
  4. Moles thread starter macrumors newbie

    Joined:
    Jul 9, 2009
    Location:
    Olathe
    #4
    So I got this created, sort of. I added two modules, the first is get selected finder file or folder and the second is run a shell script where I pass the file as a variable to the shell script. Works great with two caviats that I am hoping to get help for.

    #1: is there a way in automator to restrict the service to only running when say a .cpp file is selected in finder?

    #2 the output is always getting put at root, I want the output to go into the current folder. Is there a way to get the folder portion from the file variable that is passed in automator?

    Once I get this completed I will find somewhere to post it for anyone else who has this need. Thanks in advance for the help.
     

Share This Page