openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:
指定したファイル(複数)を指定したアプリケーションで開く
- (BOOL)openURLs:(NSArray *)urls withAppBundleIdentifier:(NSString *)bundleIdentifier options:(NSWorkspaceLaunchOptions)options additionalEventParamDescriptor:(NSAppleEventDescriptor *)descriptor launchIdentifiers:(NSArray **)identifiersfunc openURLs(_ urls: [AnyObject], withAppBundleIdentifier bundleIdentifier: String?, options options: NSWorkspaceLaunchOptions, additionalEventParamDescriptor descriptor: NSAppleEventDescriptor?, launchIdentifiers identifiers: AutoreleasingUnsafeMutablePointer<NSArray?>) -> Bool
解説
指定したファイル(複数)を指定したアプリケーションで開く
【NSWorkspaceLaunchOptions 】
NSWorkspaceLaunchAndPrint = 0x00000002,
NSWorkspaceLaunchInhibitingBackgroundOnly = 0x00000080,
NSWorkspaceLaunchWithoutAddingToRecents = 0x00000100,
NSWorkspaceLaunchWithoutActivation = 0x00000200,
NSWorkspaceLaunchAsync = 0x00010000,
NSWorkspaceLaunchAllowingClassicStartup = 0x00020000,
NSWorkspaceLaunchPreferringClassic = 0x00040000,
NSWorkspaceLaunchNewInstance = 0x00080000,
NSWorkspaceLaunchAndHide = 0x00100000,
NSWorkspaceLaunchAndHideOthers = 0x00200000,
// NSWorkspaceLaunchAndDisplayFailures
NSWorkspaceLaunchDefault = NSWorkspaceLaunchAsync |
NSWorkspaceLaunchAllowingClassicStartup
引数
URL
openURLs:(NSArray *)urls_ urls: [AnyObject]
バンドルフォルダ
Objective-C(NSString *)bundleIdentifierbundleIdentifier: String?
オプション
(NSWorkspaceLaunchOptions)optionsoptions: NSWorkspaceLaunchOptions
アップルイベントデスクリプタ
Objective-C(NSAppleEventDescriptor *)descriptordescriptor: NSAppleEventDescriptor?
(NSArray **)identifiersidentifiers: AutoreleasingUnsafeMutablePointer<NSArray?>)
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.3
更新時のバージョン
OS X 10.10.3
Swift1.2
例文
#import "SetImage.h" @implementation SetImage - (IBAction)set:(id)sender { [NSWorkspace sharedWorkspace]; NSArray *retID = [NSArray array]; NSAppleEventDescriptor* targetDesc2 = [NSAppleEventDescriptor nullDescriptor]; [[NSWorkspace sharedWorkspace] openURLs:[NSArray arrayWithObjects:[NSURL URLWithString:@"file:///Applications/iCal.app"], [NSURL URLWithString:@"file:///Applications/Chess.app"], nil] withAppBundleIdentifier:@"com.apple.Finder" options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:targetDesc2 launchIdentifiers: &retID ]; NSLog(@"%@",[retID description]); } @end
//NSWorkspace openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers: //launchIdentifiers の戻し方が不明 @IBAction func function037(sender: AnyObject) { //複製するファイルを選択 var openPanel = NSOpenPanel() openPanel.allowsMultipleSelection = true openPanel.canChooseDirectories = true openPanel.canCreateDirectories = false openPanel.canChooseFiles = true openPanel.beginWithCompletionHandler { (result) -> Void in //オープンパネルでOKを選択したら if result == NSFileHandlingPanelOKButton { //選択したファイルを複製 let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace() var asDescriptor : NSAppleEventDescriptor? = NSAppleEventDescriptor.nullDescriptor() var retID : [AnyObject?] = [] var anError: NSError? let options: NSWorkspaceLaunchOptions = .Async var result : Bool = theWorkspace.openURLs(openPanel.URLs, withAppBundleIdentifier: "com.apple.Finder", options: options, additionalEventParamDescriptor: asDescriptor , launchIdentifiers: nil ) if result { NSLog("OK ") } }//if result }//openPanel.beginWithCompletionHandler }