1

I'd like to write a script, which differ between mac and windows users, something like this:

if (Mac)
 do this
if (Windows)
 do that

This shall be a script, which starts Cmake and builds the project for the corresponding IDE. All in all:

mkdir build
cd build
if (Mac)
  cmake .. -G "Xcode"
if (Windows)
  cmake .. -G "Microsoft Visual Studio 2013"

What is the command to differ between those two machines?

I know that for windows you usually have those .bat-files, but Mac can't handle them, can it? Which file-type do I need to use here then?

5
  • You could use bash scripts. You would need to install cygwin on windows ... a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.
    – DavidPostill
    Jul 11, 2015 at 18:02
  • @DavidPostill is there a possibility without installing anything.
    – SemtexB
    Jul 11, 2015 at 18:08
  • Not as far as I know. They are completely different operating systems so there are no common default scripting languages. You have to install something on one or the other.
    – DavidPostill
    Jul 11, 2015 at 18:13
  • I don't think it's possible to write a single script, which works natively (no extra software needed) on both systems, which executes different commands based on which system it is being executed on.
    – user
    Jul 11, 2015 at 18:13
  • Ok, so best thing would be to write a script for each OS. Thank you
    – SemtexB
    Jul 11, 2015 at 18:15

2 Answers 2

0

On Windows there's cmd on Mac there's the (bash) shell. They are incompatible - you could use python instead. The bwst way is just to create a .bat/.cmd and a .sh file.

0

As Windows and Mac is unfortunately incompatible I wrote two files.

  • script_mac.command for Mac
  • script_win.bat for Windows

For Mac: As I'd like to have an executable file (script runs, when double clicking) opened by terminal (Mac) I had to type in terminal chmod +x script.command. Furthermore, I'd to choose the default app being terminal for opening script_mac.command otherwise Xcode opened the code for script_mac.command.

That pretty much did the job for Mac and Windows.

3
  • then mark it as an answer. i think instead of .command .sh should've worked too - just needed to chmld it too - but maybe them you would not have to change default app.
    – ljrk
    Jul 12, 2015 at 22:48
  • I tried it with .sh-files, but it didn't work. Maybe I missed something. Have to wait 24h before accepting.
    – SemtexB
    Jul 13, 2015 at 7:29
  • ah, ok - in my personal clock it was more than 24hrs already :D.
    – ljrk
    Jul 13, 2015 at 8:43

You must log in to answer this question.

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