[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

re: [MacPerl] copy files and launch apps



fisk@homarus.ccsu.ctstateu.edu writes:
} I'm trying to write a perl script that will copy stored preference files 
} for different users and then launch the application associated with 
} those prefs.
} 
} <background>
} Many people use the particular Mac that I work off and want their own 
} preference files for certain applications.  I would like to have a 
} script that will copy joe smith's preferences into the preference folder 
} over the existing generic one and then launch the app. When joe is done 
} he run another script to restore the prefs to the generic file.
} </background>

And for this particular job, MacPerl is the wrong tool.  Either use
straight Applescript or Frontier.

} 
} The following script (below) does not work for pref files, I'm assuming 
} because they are binarys, I tried it on some gif files as well 
} unsuccessfully.  
} 
} My question is what syntax can I use to accomplish this task?  Second 
} question I've checked the faqs and learned that the:
} exec ("app name");
} and
} @system commands do function under macperl.
} 
} How do I launch an application using macperl?

MacPerl::DoAppleScript(<<ENDIT);
launch application "blah"
ENDIT

But this is kind of pointless because Applescript itself can both copy
and rename files, and when tells the Finder to copy, it gets both
forks.  For this job its the right tool.

} 
} Zach-
} 
} 
} #!perl
} #read file write out new file script
} 
} unless (open(INFILE, "file1.txt")) {
}       die ("cannot open file\n");
} }
} 
} unless (open(OUTFILE, ">file2.txt")) {
}       die ("cannot open outfile\n");
} }
} $line = <INFILE>;
} while ($line ne "") {
}       print OUTFILE ($line);
}       $line = <INFILE>;
} }
} 

All you're really trying to do is rename the existing preference file,
right? You should just use rename(), and not try to copy the file
(especially this way). If you were doing this by hand, you wouldn't
duplicate the preference file, would you?  You'd probably just drag
(rename) the generic one out of the Preferences folder, drag (rename)
the new one in and then reverse the process when done.  I haven't
actually looked inside of one, but I'm willing to bet that most
preference files are binary, not text, and that they may have
resources.  MacPerl's I/O routines only deal with the data fork.
---
--------
Paul J. Schinder
NASA Goddard Space Flight Center,
Code 693, Greenbelt, MD 20771 USA
schinder@pjstoaster.pg.md.us