openFile:
指定したファイルを初期設定のアプリケーションで開きます
- (BOOL)openFile:(NSString *)fullPathfunc openFile(_ fullPath: String) -> Bool
解説
指定したファイル(fullPath)を初期設定のアプリケーションで開きます。
開くことができればYES(true)を返します。
そうでなければNO(false)を返します。
返り値
開けたかYES/NO(true/false)
Objective-C(BOOL)
Bool
引数
フルパス
Objective-C(NSString *)fullPath(_ fullPath: String)
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.0-
10.6-スレッドセーフ
参照
openFile:fromImage:at:inView: 非推奨
openFile:withApplication:
openFile:withApplication:andDeactivate:
openTempFile: 非推奨
更新時のバージョン
OS X 10.10.3
Swift1.2
関連記事(外部サイト)
例文
#import "SetImage.h" @implementation SetImage - (IBAction)set:(id)sender { //開けるファイル拡張子の配列 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 ] ]; } } @end//NSWorkspace openFile() @IBAction func function003(sender: AnyObject) { let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace() if theWorkspace.openFile("/Applications/Font Book.app") { NSLog("OK") }else{ NSLog("NO") } }