macOS/iOS API解説

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

目次

NSWorkspaceLaunchOptions

INDEX>AppKit>NSWorkspace

起動オプション

Objective-C

enum {
   NSWorkspaceLaunchAndPrint = 0x00000002,
   NSWorkspaceLaunchWithErrorPresentation = 0x00000040,
   NSWorkspaceLaunchInhibitingBackgroundOnly = 0x00000080,
   NSWorkspaceLaunchWithoutAddingToRecents = 0x00000100,
   NSWorkspaceLaunchWithoutActivation = 0x00000200,
   NSWorkspaceLaunchAsync = 0x00010000,
   NSWorkspaceLaunchAllowingClassicStartup = 0x00020000,
   NSWorkspaceLaunchPreferringClassic = 0x00040000,
   NSWorkspaceLaunchNewInstance = 0x00080000,
   NSWorkspaceLaunchAndHide = 0x00100000,
   NSWorkspaceLaunchAndHideOthers = 0x00200000,
   NSWorkspaceLaunchDefault = NSWorkspaceLaunchAsync | NSWorkspaceLaunchAllowingClassicStartup 
};
typedef NSUInteger NSWorkspaceLaunchOptions;

Swift

struct NSWorkspaceLaunchOptions : RawOptionSetType {
    init(_ rawValue: UInt)
    init(rawValue rawValue: UInt)
    static var AndPrint: NSWorkspaceLaunchOptions { get }
    static var WithErrorPresentation: NSWorkspaceLaunchOptions { get }
    static var InhibitingBackgroundOnly: NSWorkspaceLaunchOptions { get }
    static var WithoutAddingToRecents: NSWorkspaceLaunchOptions { get }
    static var WithoutActivation: NSWorkspaceLaunchOptions { get }
    static var Async: NSWorkspaceLaunchOptions { get }
    static var AllowingClassicStartup: NSWorkspaceLaunchOptions { get }
    static var PreferringClassic: NSWorkspaceLaunchOptions { get }
    static var NewInstance: NSWorkspaceLaunchOptions { get }
    static var AndHide: NSWorkspaceLaunchOptions { get }
    static var AndHideOthers: NSWorkspaceLaunchOptions { get }
    static var Default: NSWorkspaceLaunchOptions { get }
}

解説

launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier: openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers: で使用

●NSWorkspaceLaunchAndPrint
 開いて印刷を行う
 使用可能 OS X 10.3-

●NSWorkspaceLaunchWithErrorPresentation
 エラーが起こればエラーパネルを表示
 使用可能 OS X 10.3-

●NSWorkspaceLaunchInhibitingBackgroundOnly
 バックグラウンドのみで起動
 使用可能 OS X 10.3-

●NSWorkspaceLaunchWithoutAddingToRecents

 使用可能 OS X 10.3-

●NSWorkspaceLaunchWithoutActivation

 使用可能 OS X 10.3-

●NSWorkspaceLaunchAsync

 使用可能 OS X 10.3-

●NSWorkspaceLaunchAllowingClassicStartup

 使用可能 OS X 10.3-

●NSWorkspaceLaunchPreferringClassic

 使用可能 OS X 10.3-

●NSWorkspaceLaunchNewInstance

 使用可能 OS X 10.3-

●NSWorkspaceLaunchAndHide

 使用可能 OS X 10.3-

●NSWorkspaceLaunchAndHideOthers

 使用可能 OS X 10.3-

●NSWorkspaceLaunchDefault

 使用可能 OS X 10.3-

フレームワーク

ApplicationKit

クラス

NSWorkspace

使用可能

10.3-

更新時のバージョン

OS X 10.10.3
Swift1.2

参照

関連記事(外部サイト)

例文

Objective-C

Swift

    //NSWorkspace launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:
    //NSWorkspace NSWorkspaceLaunchOptions
    //指定のアプリを起動することはできるが、パラメータを渡すことが出来ない 調査中
    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("pURL")
        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
        }
        NSLog("%@", asDescriptor!.description as String)
    }
    //NSWorkspace openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:
    //NSWorkspace NSWorkspaceLaunchOptions
    //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

    }