openFile:withApplication:andDeactivate:
指定したファイルを、指定したアプリケーションで開きます、オプションとして、アクティブ・非アクティブをセットできます。
- (BOOL)openFile:(NSString *)fullPath withApplication:(NSString *)appName andDeactivate:(BOOL)flagfunc openFile(_ fullPath: String, withApplication appName: String, andDeactivate flag: Bool) -> Bool
解説
指定したファイルを、指定したアプリケーションで開きます。
オプションとして、アクティブ・非アクティブをセットできます。
アプリケーションはフルパスで指定しなくてもアプリケーション名だけでいいです。
appNameがnilなら、ファイルのタイプ用のデフォルトのアプリケーションが使われます。
開くことができればYESを返します。
そうでなければNOを返します。
返り値
開けたかYES/NO
Objective-C(BOOL)
Bool
引数
フルパス
Objective-C(NSString *)fullPath_ fullPath: String
アプリ名
Objective-C(NSString *)appNameappName: String
アクティブかYES/NO
Objective-C(BOOL)flag
flag: Bool
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.0
参照
openFile:
openFile:withApplication:
application:openFile:(NSApplication)
更新時のバージョン
OS X 10.10
関連記事(外部サイト)
例文
//開けるファイル拡張子の配列 NSArray *fileTypes = [ NSArray arrayWithObject : @"tiff" ]; //OpenPanelを作る NSOpenPanel *opPanel = [ NSOpenPanel openPanel ]; //OpenPanelの結果のボタン番号 int opRet; BOOL openResult; //OpenPanelでファイル選択 opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Pictures" //どのどのファイルを選択しておくか types : fileTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら openResult = [[NSWorkspace sharedWorkspace] openFile:[ opPanel filename ] withApplication:@"QuickTime Player" andDeactivate:NO ]; }//NSWorkspace openFile:withApplication:andDeactivate: @IBAction func function005(sender: AnyObject) { let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace() let theFilePath : NSString = NSString(string: "~/Desktop/textured.gif") //チルダ付きのファイルパスをフルパスに変換する let fileFullPath : NSString = theFilePath.stringByExpandingTildeInPath NSLog(fileFullPath) if theWorkspace.openFile(fileFullPath, withApplication:"Preview", andDeactivate: true) { NSLog("OK") }else{ NSLog("NO") } }