initWithSource:
ソーステキストからアップルスクリプトオブジェクトを初期化して返します
-(id)initWithSource:(NSString *)source:
解説
ソーステキストからアップルスクリプトオブジェクトを初期化して返します。
返り値
( id )
オブジェクト(NSAppleScript)
引数
( NSString * )source
アップルスクリプトソース
フレームワーク
Foundation
クラス
NSAppleScript
Instance Methods
使用可能
10.2
参照
例文
#import "SetImage.h" @implementation SetImage - (IBAction)set:(id)sender { //開けるファイル拡張子の配列 NSArray *imgTypes = [ NSArray arrayWithObjects : @"txt",@"TEXT",nil ]; //OpenPanelを作る NSOpenPanel *opPanel = [ NSOpenPanel openPanel ]; //Imageを作る NSAppleScript *script; NSString *source; NSDictionary *error; //OpenPanelの結果のボタン番号 int opRet; //OpenPanelでファイル選択 opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Documents" //どのファイルを選択しておくか types : imgTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら //NSImageを作ってファイルから読み込む source = [NSString stringWithContentsOfURL:[NSURL fileURLWithPath:[opPanel filename]]]; script = (NSAppleScript *)[ [ NSAppleScript alloc ] initWithSource:source ]; [script executeAndReturnError:&error]; } } @end