如何使用NSWorkspace launchApplicationAtURL? [英] How to use NSWorkspace launchApplicationAtURL?

查看:1061
本文介绍了如何使用NSWorkspace launchApplicationAtURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 launchApplicationAtURL 运行等效于TextMate foo.txt。二进制文件的名称是TextMate,我有一个参数。

I tried to run equivalent of "TextMate foo.txt" using launchApplicationAtURL. The name of binary is "TextMate", and I have one parameter.

我试过下面的代码,但似乎不工作。

I tried the following code, but it doesn't seem to work.

// find the textmate
NSURL * bURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.macromates.textmate"];
NSWorkspace * ws = [NSWorkspace sharedWorkspace];

// find the parameter
NSString * f = @"foo.txt";
NSArray  * myArray2 = [NSArray arrayWithObjects:f,nil];

NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
[dict setObject:myArray2 forKey:NSWorkspaceLaunchConfigurationArguments];

[ws launchApplicationAtURL:bURL options:NSWorkspaceLaunchDefault configuration:dict error:nil];

这有什么问题?

我检查这个代码实际上是工作,我有一些问题,如何'TextMate.app'处理参数。

I checked this code actually works, I got something wrong with how 'TextMate.app' deals with the parameters.

推荐答案

大多数应用程序不使用命令行参数。如果要使用特定应用程序打开特定文件,请使用 - [NSWorkspace openFile:withApplication:]

Most apps don't use command line parameters. If you want to open a particular file with a particular app, use -[NSWorkspace openFile:withApplication:].

这篇关于如何使用NSWorkspace launchApplicationAtURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆