macOS/iOS API解説

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

目次

executeAndReturnError:

Index>Foundation>NSAppleScript

アップルスクリプトオブジェクトを実行します
-(NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo:

解説

アップルスクリプトオブジェクトを実行します。

返り値

( NSAppleEventDescriptor * )

アップルイベントデスクリプタ

引数

( NSDictionary ** )errorInfo

エラー情報

クラス

NSAppleScript

Instance Methods

使用可能

10.2

参照

例文

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{
    //開けるファイル拡張子の配列
    NSArray      *imgTypes    = [ NSArray arrayWithObject : @"script" ];
    //OpenPanelを作る
    NSOpenPanel  *opPanel       = [ NSOpenPanel openPanel ];
    //を作る
    NSAppleScript      *script;
    
    NSDictionary *error;
    //OpenPanelの結果のボタン番号
    int		  opRet;
     
        //OpenPanelでファイル選択   
    opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Documents" //どのファイルを選択しておくか
                                    types : imgTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
        //ファイルから読み込む
        script = [ [ NSAppleScript alloc ] 
                          initWithContentsOfURL:
                          [NSURL fileURLWithPath:[opPanel filename]]
                          error:&error
                          ];
         [script executeAndReturnError:&error];
         NSLog([error description]);

    }
}

@end