launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:
バンドルIDで指定したアプリケーションを起動します
- (BOOL)launchAppWithBundleIdentifier:(NSString *)bundleIdentifier options:(NSWorkspaceLaunchOptions)options additionalEventParamDescriptor:(NSAppleEventDescriptor *)descriptor launchIdentifier:(NSNumber **)identifierfunc launchAppWithBundleIdentifier(_ bundleIdentifier: String, options options: NSWorkspaceLaunchOptions, additionalEventParamDescriptor descriptor: NSAppleEventDescriptor?, launchIdentifier identifier: AutoreleasingUnsafeMutablePointer<NSNumber?>) -> Bool
解説
バンドルIDで指定したアプリケーションを起動します。
返り値
- (BOOL)launchAppWithBundleIdentifier:(NSString *)bundleIdentifier options:(NSWorkspaceLaunchOptions)options additionalEventParamDescriptor:(NSAppleEventDescriptor *)descriptor launchIdentifier:(NSNumber **)identifierfunc launchAppWithBundleIdentifier(_ bundleIdentifier: String, options options: NSWorkspaceLaunchOptions, additionalEventParamDescriptor descriptor: NSAppleEventDescriptor?, launchIdentifier identifier: AutoreleasingUnsafeMutablePointer<NSNumber?>) -> Bool
メニュー
引数
バンドルID
@"com.apple.iCal"などの形式(NSString *)bundleIdentifier_ bundleIdentifier: String
起動オプション
Objective-C
【NSWorkspaceLaunchOptions 】起動オプション
●NSWorkspaceLaunchAndPrint 開いて印刷する
●NSWorkspaceLaunchInhibitingBackgroundOnly バックグラウンドで開く
●NSWorkspaceLaunchWithoutAddingToRecents
●NSWorkspaceLaunchWithoutActivation アプリケーションを開くが前面には持ってこない
●NSWorkspaceLaunchAsync 非同期で起動する
●NSWorkspaceLaunchAllowingClassicStartup クラシック環境で起動する
●NSWorkspaceLaunchPreferringClassic クラシック環境で起動する
●NSWorkspaceLaunchNewInstance 先にアプリケーションがあったらもうひとつインスタンスを作って起動する
●NSWorkspaceLaunchAndHide 起動してすぐに隠す
●NSWorkspaceLaunchAndHideOthers 起動して他のアプリケーションを隠す
●NSWorkspaceLaunchDefault = NSWorkspaceLaunchAsync |
NSWorkspaceLaunchAllowingClassicStartup(NSWorkspaceLaunchOptions)optionsSwift
【NSWorkspaceLaunchOptions 】起動オプション
NSWorkspaceLaunchOptions
.AndPrint
.WithErrorPresentation
.InhibitingBackgroundOnly
.WithoutAddingToRecents
.WithoutActivation
.Async
.AllowingClassicStartup
.PreferringClassic
.NewInstance
.AndHide
.AndHideOthers
.Defaultoptions: NSWorkspaceLaunchOptions
起動するアプリケーションに渡されるアップルイベントデスクリプタ
開く文書を指定する時などに渡す。
Objective-C(NSAppleEventDescriptor *)descriptordescriptor: NSAppleEventDescriptor?
起動IDが返される
Objective-C(NSNumber **)identifieridentifier: AutoreleasingUnsafeMutablePointer<NSNumber?>
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.3
更新時のバージョン
OS X 10.10.3
Swift1.2
例文
#import "SetImage.h" @implementation SetImage - (IBAction)set:(id)sender { [NSWorkspace sharedWorkspace]; NSNumber *num = [[NSNumber alloc] init] ; NSAppleEventDescriptor* targetDesc2 = [NSAppleEventDescriptor nullDescriptor]; [[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:@"com.oomori.monzai" //@"com.apple.iCal" options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:targetDesc2 launchIdentifier: &num ]; NSLog(@"%@",[[num longValue] description]); } @end
Swift
指定のアプリを起動することはできるが、パラメータを渡すことが出来ない。調査中です。
//NSWorkspace launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier: //指定のアプリを起動することはできるが、パラメータを渡すことが出来ない func val4 (s: String) -> UInt32 { var n: UInt32 = 0 var r: String = "" if (count(s) > 4) { r = s.substringToIndex(advance(s.startIndex, 4)) } else { r = s + " " r = r.substringToIndex(advance(r.startIndex, 4)) } for UniCodeChar in r.unicodeScalars { n = (n << 8) + (UInt32(UniCodeChar.value) & 255) } return (n) } @IBAction func function036(sender: AnyObject) { let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace() //var asDescriptor : NSAppleEventDescriptor? = NSAppleEventDescriptor.nullDescriptor() var urlDescriptor : NSAppleEventDescriptor? = NSAppleEventDescriptor(string: "http://www.apple.com/") var asDescriptor : NSAppleEventDescriptor? = NSAppleEventDescriptor.recordDescriptor() let aeKeyword : AEKeyword = val4("URL") asDescriptor?.setParamDescriptor(urlDescriptor!, forKeyword: aeKeyword ) var launchID : NSNumber? = NSNumber() var result : Bool = theWorkspace.launchAppWithBundleIdentifier("com.apple.safari", options: NSWorkspaceLaunchOptions.Default, additionalEventParamDescriptor: asDescriptor, launchIdentifier: &launchID ) if result { NSLog("launchID %d",launchID!) // -> launchID 311 } }