Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > copyPath:toPath:handler:

copyPath:toPath:handler:
Thread Tools
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jul 19, 2002, 06:20 PM
 
Im writing a prefpane that will have the ability to create a startup item for the daemon that the prefPane controls. This startup item is a folder included in the prefPane bundle. At this point im just trying to get the folder and its contents to copy to my desktop but it never works. No files are copied. Here is my code thus far:

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> - (void) createStartupItem {

NSString *source = [[NSBundle bundleForClass:[self class]] pathForResource:@&quot;theStartupItemFolderWit hStuffInIt&quot; ofType:@&quot;nil&quot;];
NSString *destination = NSHomeDirectory();
[[NSFileManager defaultManager] copyPath:source toPath:destination handler:nil];

}

Where have I strayed?


</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
3R1C
     
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 19, 2002, 07:15 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by 3R1C:
<strong> NSString *source = [[NSBundle bundleForClass:[self class]] pathForResource:@"theStartupItemFolderWithStuffInI t" ofType:@"nil"];
</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">this mmight be the offending line. @"nil" is a string containing "nil", what you most probably mean is "...ofType:nil", a "real" nil-object.
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jul 19, 2002, 09:17 PM
 
You're right about the error you found (I should have caught that one) but it still doesn't copy.
3R1C
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 20, 2002, 02:11 AM
 
Why don't you implement a handler? That might tell you something.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 20, 2002, 03:07 AM
 
just had a look at the apis... looks as if the source would have to include a filename; so instead of copying it to "~", try [@"~/Desktop/theStartupItemFolderWithStuffInIt" stringByExpandingTildeInPath] and let us know whether that did it.
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jul 20, 2002, 08:18 AM
 
Yup. that did it. Now on to the meat of the matter. How can I use the security framework to execute this command? I already am able to use the security framework to execute shell commands to do commands but how do I execute an [NSFileManager defaultManager] copyPath ?do I need to include cpMac in my bundle and execute the path copy with it using priveleges?
3R1C
     
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 20, 2002, 09:00 AM
 
why re-invent the wheel?

why not create an installer package with packagemaker, put it inside your bundle and then use nsworkspace to open it which would launch the installer?
the installer knows how to put stuff where, can ask for authorization, you could supply an additinal readme in it,... also, personally i'd rather trust the installer -- sorry, nothing personal.

plus, it's way easier <img border="0" title="" alt="[Wink]" src="wink.gif" />
     
3R1C  (op)
Mac Enthusiast
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jul 20, 2002, 02:04 PM
 
Well, because the startup item that is written, needs to be generated on the fly, depending upon who's library, the prefpane is in. if its in a user prefpane folder, then a startup item must be written out that points to that users item to startup. and I cant use $HOME in the startup item because, the startup item runs as root, and also because there is no user yet. startup items load before there is a user. Not to mention that it wouldn't be very user friendly if every time my user checks the "create startup item' in my prefpane, they run installer. Right now, im using the BLAuthentication object, I found at stepwise. It works like a champ but it only seems to authorize NSTasks, not actual obj c commands in my code. Im not sure if startup items have a resource fork or not. If they do, i need to use the BLAuthenticate object to authorize a cpMac to put my on the fly generated startup item where it needs to go. If this is true I'll need to put cpMac in my bundle. If my startup item does not have a resource fork, I can just use the cp command that the user already has on his box. All of this could be avoided if I could just use the authorization Services framework to do obj c commands instead of an NSTask.
whew.
3R1C
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jul 20, 2002, 02:36 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by 3R1C:
<strong>Yup. that did it. Now on to the meat of the matter. How can I use the security framework to execute this command? I already am able to use the security framework to execute shell commands to do commands but how do I execute an [NSFileManager defaultManager] copyPath ?do I need to include cpMac in my bundle and execute the path copy with it using priveleges?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Any admin user should be able to write to /Library/StartupItems.
     
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 20, 2002, 03:09 PM
 
a .pkg is nothing but a package, you could easily assemble it on the fly.

but i don't see anything wrong with invoking cp and using the shell to copy stuff -- as you like. the question is not "do startup items have a resource fork?" but "does *your* startup item have a resource fork?"
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:05 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2