Fopen file creation with set permissions

I've been making a mel tool that will write out a batch render shell script for me based on the scenes I give it. My only real issue these days is that I have to first ceate a text file with ".sh" extension and set the permisions, then I can get maya to edit that file.

If I use this code below I can get maya to create the text file for me, but its permisions are still not set correctly.  
I have to then take that file and run chmod 755 on it in the terminal (I'm on a mac) before i can run it. 

$FileName = ("/Users/myUser/Desktop/File.sh");

$fileId = fopen $FileName "w";

fprint $fileId "A bunch of text\n";

fclose $fileId;

The maya docs on fopen are pretty limited and I 've been searching the web in vain, but does anyone know if its possible to set the permissions on a file when fopen creates it so that I can alleviate that whole extra step of editing  the permisions after the fact?

Thnx -DD 

have to then take that file and run chmod 755 on it in the terminal

use the system command

but does anyone know if its possible to set the permissions on a file when fopen creates

no dont think so, use a sytem command to chmod. Only commads that make sense across sytems make really sense. So if it has no menaing in windows but does have maning in linux and OSX, then implement the separate changes in the separate commands. Now since the stuff your doing is not sytem independent anyway doing one extra system call is not a big deal.

I have to first ceate a text file with ".sh" extension

Actually it doesnt really matter what the extension is. Thats whty you need to chmod things.

 So I got it working with the following script. Take it with a grain of salt, this was just me testing some stuff- but it works on a mac at least.

//////---------------------------------------- 

string $array[] = {"red","orange","blue"};

string $scriptBody = "I'm a bunch of text";

string $getTxtPath[] = fileDialog2 -fileMode 4 -dialogStyle 1; //Find Current File

string $TxtPath = $getTxtPath[0]; //Make path string NOT string[]

string $dirname = dirname($TxtPath); //Get Directory name

string $dirname = $dirname + "/"; //Append a slash to Directoryname

string $NameWithExtension = match "[^/\\]*$" $TxtPath; //Remove Path from File Name

string $Name = match "^[^\.]*" $NameWithExtension; //Remove extension from file name

string $makeSubTextDir = sysFile -makeDir ($dirname + $Name); //Create directory with the name of file name in same directory as current shell

for($i=0;$i<size($array);$i++){ //Create a shell script in the new directory for each item in array

  $createBlankShell = ($dirname + $Name + "/" + $Name + "_" + $array[$i] + ".sh");

  $fileId = fopen $createBlankShell "w";

  fprint $fileId $scriptBody;

  fclose $fileId;

  system ("chmod 755 \"" + $createBlankShell + "\"");

}