Re: [Cocoa]Re: Creating an alias
Re: [Cocoa]Re: Creating an alias
- Subject: Re: [Cocoa]Re: Creating an alias
- From: Kris Amico <email@hidden>
- Date: Mon, 03 Mar 2003 23:13:02 -0800
Given an AppleScript looking something like:
tell application "Finder"
make new alias file at desktop to alias "$MY_PATH"
end tell
You could replace the token with the HFS-style path to your application.
This style of path may be obtained with CFURLCopyFileSystemPath. Now, what
to do with the script can vary according to your baseline.
On 10.2, it should be pretty easy from here; you may use NSAppleScript. On
10.1 and up, you may launch osascript, sample code for which is below.
Given "scriptString", an NSString containing your AppleScript...
// run AppleScript by launching osascript:
NSTask* osaTask = [[[NSTask alloc] init] autorelease];
NSPipe* osaInputPipe = [NSPipe pipe];
NSPipe* osaOutputPipe = [NSPipe pipe];
[osaTask setLaunchPath:@"/usr/bin/osascript"];
[osaTask setArguments:[NSDictionary dictionary]];
[osaTask setStandardInput:osaInputPipe];
[osaTask setStandardOutput:osaOutputPipe];
NSFileHandle* osaInput = [[osaTask standardInput] fileHandleForWriting];
[osaTask launch];
[osaInput write
Data:[scriptString dataUsingEncoding:NSUTF8StringEncoding
allowLossyConversion:YES]];
[osaInput closeFile];
[osaTask waitUntilExit];
If you wish to print out the result, just read osaOutputPipe. I think that
in the above code, you may have a bit of a string encoding problem; keep in
mind it's just a sample. In fact, you may forgo all that together and use
the scripting APIs in Cocoa.
On 3/3/03 10:02 PM, "Ben Mackin" <email@hidden> wrote:
>
On 3/3/03 7:06 PM, "Kris Amico" <email@hidden> wrote:
>
>
So as the argument I would pass the script? So something like (uncompiled):
>
>
osascript=[[NSTask alloc] init];
>
[osascript setLaunchPath:@"/usr/bin/osascript"];
>
[osascript setArguments:[NSArray arrayWithObjects:@"tell application
>
\"Finder\"\rmake new alias at \"/Library/PDF Services/Fax this Document\" to
>
\"/Applications/Cocoa eFax/Cocoa eFax.app\"\rend tell", nil]];
>
[osascript launch];
>
>
I know that script doesn't compile. I am not really an AppleScript whiz, and
>
am not sure how to get the make new alias thing to work. I tried looking on
>
Apples site, but couldn't find any example scripts for making aliases. Any
>
help would be appreciated :)
>
--
Kris Amico <email@hidden>, AIM: Kris Amico
Senior Software Engineer
Macintosh Client Software Development
EarthLink, Inc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.