0

I have an Mac Application, and when I launch it the first time, a file should be copied. Is there a way to do this?

I can do a "Build Phase" in Xcode that looks like this:

Type:          Copy files
Destination:   Absolute Path
Subpath:       /Local/Targetfolder

But this does not seem to copy the desired file, when running the app. If possible I don't want to create an Installer for my Application.

Edit: I should note that my Application depends on the copied file (Yes, yes I know!). So I can't do this in Code because the App would crash otherwise.

Besi
  • 22,579
  • 24
  • 131
  • 223

1 Answers1

2

How about just (in your code) doing something like;

if ( [[NSFileManager defaultManager] isReadableFileAtPath:source] &&
    ![[NSFileManager defaultManager] isReadableFileAtPath:destination])
    [[NSFileManager defaultManager] copyItemAtURL:source toURL:destination error:nil];

That should just plain copy the file if it's missing.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • Thanks for your suggestion, is there a way to do this prior to the launch of the applicaiton similar to the case when an App provides a QuickLookplugin or a Spotlightimporter... – Besi Feb 01 '12 at 17:40
  • Without an installer I don't know of a way (I'm sure someone will correct me if there is a way), couldn't you just do it first thing in your code? Was thinking if the file is missing due to some other reason you may want to copy it again anyway? – Joachim Isaksson Feb 01 '12 at 17:42
  • It would have to happen prior to the launch because the application depends on it. I know this might sound horrible (actually it is). But it is a workaround because my App is looking in the wrong place for a `.framework`. See this post: http://stackoverflow.com/q/9098371 – Besi Feb 01 '12 at 17:46
  • @Besi Since you'll need to be root to write to /Library/Frameworks, I know of only 2 ways; either make a small launcher app that will ask for admin permission and copy the file if it doesn't exist and when it's done launch the secondary app, or make a real installer. – Joachim Isaksson Feb 01 '12 at 18:49