이미 하나의 옵션을 찾을 수 없었지만 (여전히 일부는 존재할 수 있습니다) 그래서 하나를 작성했습니다. 기본적으로 앱에 브라우저가 기본 브라우저 (#define SET_AS_DEFAULT_BROWSER
참조)로 설정되고 마지막으로 URL을 이라는 스크립트에 전송하여 올바른 이벤트를 수신하면 URL을 관리합니다. 앱의 번들 (즉, .app 디렉토리 내부). 라는 bash는 명령은 다음과 같습니다
nohup /path/to/my_link_opener "_an_url_" >& /dev/null &
#import "ZFTAppDelegate.h"
NSString *runCommand(NSString *commandToRun)
{
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/sh"];
NSArray *arguments = @[@"-c" ,[NSString stringWithFormat:@"%@", commandToRun]];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *output;
output = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
return output;
}
#define SET_AS_DEFAULT_BROWSER
@implementation ZFTAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
[em setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
[em setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:'WWW!'
andEventID:'OURL'];
#ifdef SET_AS_DEFAULT_BROWSER
CFStringRef bundleID = (__bridge CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
LSSetDefaultHandlerForURLScheme(CFSTR("http"), bundleID);
LSSetDefaultHandlerForURLScheme(CFSTR("https"), bundleID);
#endif
}
- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSString* scriptPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"my_link_opener"];
runCommand([NSString stringWithFormat:@"nohup %@ \"%@\" >& /dev/null &", scriptPath, url]);
}
@end
이 응용 프로그램의 Info.plist 파일에 그 기억 당신이해야이이 (HTTP/s의 URL을 처리하기 위해 응용 프로그램의 기능에 대해 OS를 알릴 필요) :
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>https</string>
</array>
<key>CFBundleURLName</key>
<string>Secure http URL</string>
</dict>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>http</string>
</array>
<key>CFBundleURLName</key>
<string>http URL</string>
</dict>
</array>
왜'-psn_xxxxx' 옵션을 관리하고 그 각 옵션의'my_link_opener'의 새로운 인스턴스를 시작 Appify에 싸여 다른 스크립트를 가지고 있지? –
그게 옵션이라고 생각합니다. 아무도 이미 해본 적이 없습니까? 배우는 것이 무척 힘듭니다. – Linus
AFAIK 아니요. 하지만 나중에 확인하겠습니다 –