On Sep 24, 2008, at 12:14 AM, chaitanya pandit wrote:


On 24-Sep-08, at 5:10 AM, Charles Srstka wrote:

On Sep 23, 2008, at 5:02 PM, Nick Zitzmann wrote:

On Sep 23, 2008, at 3:57 PM, chaitanya pandit wrote:

It created an executable file with name foobar alias on desktop but when i try to open it it says "chaitanya-pandits-macbook:~ chaitanya$ /Users/chaitanya/Desktop/ foobar\ alias ; exit; -bash: /Users/chaitanya/Desktop/foobar alias: cannot execute binary file
logout
[Process completed]"

Any idea what i'm doing wrong?


You're using an alias file; that's what you're doing wrong. As I said, only Carbon and certain AppKit classes resolve aliases. BASH doesn't use Carbon or AppKit; it uses lower level stuff that doesn't resolve aliases. You'll have to use links (hard or symbolic) instead.

From the looks of it, it doesn't sound like she's trying to use an alias in bash; more likely, she's trying to create an alias file that she would double-click in the Finder, but she's doing it incorrectly in such a manner that LaunchServices is guessing that the file is an executable and thus trying to open it with the Terminal.

Thats exactly what i'm trying to accomplish, and bye the way i am "he" :)

Whoops, my apologies.

I think this code should do what you want:

- (BOOL)makeAliasFile:(NSString *)destPath originalFile:(NSString *)originalPath { NSMutableString *source = [NSMutableString stringWithString:@"tell application \"Finder\"\n"];

[source appendFormat:@"set theAlias to make alias at POSIX file \"[EMAIL PROTECTED]" to POSIX file \"[EMAIL PROTECTED]"\n", NSTemporaryDirectory(), originalPath];
    [source appendFormat:@"get POSIX path of (theAlias as string)\n"];
    [source appendFormat:@"end tell"];

NSAppleScript *script = [[[NSAppleScript alloc] initWithSource:source] autorelease];

    NSDictionary *error = nil;
NSAppleEventDescriptor *desc = [script executeAndReturnError:&error];

    if(desc == nil) {
        return NO;
    } else {
return [[NSFileManager defaultManager] movePath:[desc stringValue] toPath:destPath handler:nil];
    }
}

It would also be possible to use the resource-fork method described earlier in this thread, but the method above is probably the method that is least likely to break (for example, if Apple ends up switching to a new file system that uses something other than the resource fork to store its aliases, then building them yourself in that fashion could conceivably stop working).

HTH,
Charles
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to