selectFile:inFileViewerRootedAtPath:
指定ファイルをFinderで表示します
- (BOOL)selectFile:(NSString *)fullPath inFileViewerRootedAtPath:(NSString *)rootFullPathfunc selectFile(_ fullPath: String, inFileViewerRootedAtPath rootFullPath: String) -> Bool
解説
指定ファイルをFinderで表示します。
フルパスで指定すると、新しいウインドウで表示されます。
表示できればYESを返します。
そうでなければNOを返します。
10.5以降ではシンボリックリンクを自動的に解決しません。
シンボリックリンクを解決するためには事前にstringByResolvingSymlinksInPathで解決しておいてください。
返り値
選択できたかYES/NO
Objective-C(BOOL)
Bool
引数
表示するファイルのフルパス
Objective-C(NSString *)rootFullPathrootFullPath: String
ルートフルパス
Objective-C- (BOOL)selectFile:(NSString *)fullPath inFileViewerRootedAtPath:(NSString *)rootFullPathfunc selectFile(_ fullPath: String, inFileViewerRootedAtPath rootFullPath: String) -> Bool
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.0
参照
更新時のバージョン
OS X 10.10
関連記事(外部サイト)
例文
//開けるファイル拡張子の配列 NSArray *fileTypes = [ NSArray arrayWithObject : @"tiff" ]; //OpenPanelを作る NSOpenPanel *opPanel = [ NSOpenPanel openPanel ]; //OpenPanelの結果のボタン番号 int opRet; BOOL selectResult; //OpenPanelでファイル選択 opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Pictures" //どのどのファイルを選択しておくか types : fileTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら selectResult = [[NSWorkspace sharedWorkspace] selectFile:[ opPanel filename ] inFileViewerRootedAtPath:@"" ]; }
//NSWorkspace selectFile:inFileViewerRootedAtPath: @IBAction func function016(sender: AnyObject) { //ファイルを選択 var openPanel = NSOpenPanel() openPanel.allowsMultipleSelection = false openPanel.canChooseDirectories = false openPanel.canCreateDirectories = false openPanel.canChooseFiles = true openPanel.beginWithCompletionHandler { (result) -> Void in //オープンパネルでOKを選択したら if result == NSFileHandlingPanelOKButton { //選択したファイルを let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace() let theURL : NSURL = openPanel.URL! let filepath : NSString = theURL.path! theWorkspace.selectFile(filepath, inFileViewerRootedAtPath: "" ) }//if result }//openPanel.beginWithCompletionHandler }