macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

Workspace 起動設定オプション

INDEX>AppKit>NSWorkspace

起動オプション

Objective-C

NSString * const NSWorkspaceLaunchConfigurationAppleEvent;
NSString * const NSWorkspaceLaunchConfigurationArguments;
NSString * const NSWorkspaceLaunchConfigurationEnvironment;
NSString * const NSWorkspaceLaunchConfigurationArchitecture;

Swift

let NSWorkspaceLaunchConfigurationAppleEvent: String
let NSWorkspaceLaunchConfigurationArguments: String
let NSWorkspaceLaunchConfigurationEnvironment: String
let NSWorkspaceLaunchConfigurationArchitecture: String

解説

launchApplicationAtURL:options:configuration:error: メソッドで使用

NSWorkspaceLaunchConfigurationAppleEvent
  アップルイベント
NSWorkspaceLaunchConfigurationArguments
  起動時の引数
NSWorkspaceLaunchConfigurationEnvironment
  環境変数

NSWorkspaceLaunchConfigurationArchitecture
 アーキテクチャ
 NSBundleExecutableArchitectureI386
  386
 NSBundleExecutableArchitecturePPC
  PowerPC
 NSBundleExecutableArchitectureX86_64
  x86 64ビット
 NSBundleExecutableArchitecturePPC64
  PowerPC 64ビット

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.6-

更新時のバージョン

OS X 10.10.3
Swift1.2

参照

cocoaapi.hatenablog.com

関連記事(外部サイト)

Mac OSで関数をフックする方法


github.com

例文

Objective-C

Swift

    //NSWorkspace launchApplicationAtURL:options:configuration:error:
    @IBAction func function009(sender: AnyObject) {
        let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace()
        var anError: NSError?
        let andPrint = NSWorkspaceLaunchOptions.AndPrint.rawValue
        let mask = Int( andPrint ) // cast from UInt
        
        let theURL : NSURL = NSURL(fileURLWithPath: "/Applications/iTunes.app")!
        let theOption : NSNumber = NSNumber(integer: 0)
        //32ビットモードで起動
        let theArc : NSNumber = NSNumber(integer: NSBundleExecutableArchitectureI386)
        //64ビットモードで起動
        //let theArc : NSNumber = NSNumber(integer: NSBundleExecutableArchitectureX86_64)
        
        let theConfig : [NSObject : AnyObject] = [NSWorkspaceLaunchConfigurationArchitecture : theArc]
        if (theWorkspace.launchApplicationAtURL(theURL,
                options: NSWorkspaceLaunchOptions.Async,
                configuration: theConfig,
                error: &anError) != nil){
            NSLog("YES")
        }else{
            NSLog("NO")
        }

        

    }