Needing help with a script

trey5498

Registered
I have asked 2 questions before and both times when I asked them I was given good pointers but ended up figure it out myself. I am here once again in an attempt to ask a question and hopefully be able to solve it with your help.

What I am looking for is a way to install your choice of 1 to 26 items at a time (installing multiple from the list if so choose) with a switch at the bottom to allow you to select all of them. I will need to run a check of the os since the files that need to be checked for are in 2 different spots in 10.4 and 10.5

run down on what i need:

- Check the os version and place it in the variable
- check if a file exists in the folder, if not, then copy it there
- a way to install the items that the user selects

I am attempting to use xcode, however, I was wondering if there is a better program to use. I know that i will need to have an array to copy the items to so it will be read into.

Please help me or point me in the right direction again.
 
Have you considered building a package for use with the standard Installer.app? It sounds like what you need is what that was built for. I have little experience with it, though, so I'm not sure exactly how you'd rig it up.

If you want to deal with XCode, you can use the methods detailed at Cocoa Dev Central for testing which Mac OS version the user has. I recommend method #2 on that page. The first one won't work beyond Panther, and the last one is just complicated.

To check and copy files, look up NSFileManager. Specifically, the fileExistsAtPath:isDirectory: and copyPath:toPath:handler: methods.
 
If you want to deal with XCode, you can use the methods detailed at Cocoa Dev Central for testing which Mac OS version the user has. I recommend method #2 on that page. The first one won't work beyond Panther, and the last one is just complicated.

I'm with Mikuro, I prefer method #2 as well. For the original poster to differentiate between 10.4 and 10.5 it's no problem, but for finer control it's a but lacking since it will report anything after 10.4.9 (10.4.10, 10.4.11....) the same.

So for others who find this post and might be looking for more than just the minor revision number, here's a program which uses the original code, and a proposed modification. Output on Tiger (currently 10.4.11) looks like this, where the original method reports the OS as 10.4.9, and the modification shows 10.4.11:

0x1049
10.4.11

Code:
// os.c
// Compile with:  gcc -o os os.c -framework Carbon
#include <stdio.h>
#include <Carbon/Carbon.h>

void OriginalMethod()
{
  SInt32 macVersion = 0;
  if (Gestalt(gestaltSystemVersion, &macVersion) == noErr) {
    fprintf(stderr,"0x%4x\n", macVersion);
  } else {
    fprintf(stderr,"Gestalt error\n");
  }
}

void ModifiedMethod()
{
  SInt32 osVersion[3] = {0, 0, 0};
  if (Gestalt(gestaltSystemVersionMajor, &osVersion[0]) == 
    Gestalt(gestaltSystemVersionMinor, &osVersion[1]) ==
    Gestalt(gestaltSystemVersionBugFix,&osVersion[2]) == noErr) {
    fprintf(stderr,"%d.%d.%d\n", osVersion[0], osVersion[1], osVersion[2]);
  } else {
    fprintf(stderr,"Gestalt error\n");
  }
}

int main(void)
{
  OriginalMethod();
  ModifiedMethod();
}

Edit: Interesting. I just found this in Gestalt.h (look in /System/Library/Frameworks/CoreServices.framework....)

A better way to get version information on Mac OS X would be to read in the
system version information from the file /System/Library/CoreServices/SystemVersion.plist.

I don't have access to anything older than 10.4 any more so I don't know if this is valid in older versions of the OS. In any case SystemVersion.plist on 10.4 includes this:

Code:
        <string>Mac OS X</string>
        <key>ProductUserVisibleVersion</key>
        <string>10.4.11</string>
        <key>ProductVersion</key>
        <string>10.4.11</string>
 
Last edited:
Back
Top