私の最初の選択肢は、アプリケーションにウィンドウのようなファインダーを作成し、その中でファイルを開くことです。これにより、アクションを完全に制御できます。
2 番目のオプションは、スクリプト可能なココア アプリを作成することです。これにより、質問で説明した機能が提供され、サンドボックスと互換性があります。Apple から: Gatekeeper と Signing Applets。
上のリンクからまとめます。
ゲートキーパーと署名アプレット OS X Mountain Lion には、ダウンロードしたソフトウェアの実行を許可するポリシーを適用することで、悪意のあるソフトウェアからユーザーを保護するゲートキーパーが含まれています。ゲートキーパーはコード署名に依存してアプリケーションを検証します。署名されたアプリケーションは、署名者によって作成され、署名後に変更されていないことが保証されます。デフォルトでは、Gatekeeper は、Mac App Store または識別された開発者によって署名されたアプリケーションのみの実行を許可します。配布用のスクリプト アプリケーション (「アプレット」) を作成する場合、このポリシーがアプレットに適用されます。アプレットに署名して、Gatekeeper のデフォルト ポリシーによってブロックされないようにするには:
私たちの必要なもの:
- アプリケーションのスクリプト可能性情報を定義する *.sdef ファイルを作成します。スクリプタビリティ情報
- アプリへの Cocoa スクリプト サポートの追加 スクリプト可能なアプリケーションの Cocoa サポート
- Applescript を作成して、「名前付き」の Finder ウィンドウを開き、Cocoa アプリに情報を送り返したり、その逆を行ったりします。
- アプリから Applescript を呼び出すか、その逆を行います。
*.sdef ファイルを作成する必要があります。これは、一連のスクリプト機能に関する用語と、アプリケーションのスクリプト機能を説明するコマンド、クラス、定数、およびその他の情報を記述した XML ベースの形式です。このファイルをプロジェクトに追加する必要があります。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="YOUR_APP_NAME">
<suite name="scriptTest Suite" code="MApN" description="YOUR_APP_NAME Scripts">
<command name="myFirstCommand" code="lkpstrng" description="The array to lookup">
<cocoa class="MyLookupCommand"/>
<direct-parameter description="The array to lookup">
<type type="any" list="yes"/>
</direct-parameter>
<result description="returns and array" type="text"/>
</command>
</suite>
</dictionary>
*.sdef ファイルをプロジェクトに含めた後、2 つの新しいキーを info.plist に追加する必要があります。Scriptable = YES およびスクリプト定義ファイル名。

cocoa class
として定義されたスクリプト定義ファイルMyLookupCommand
では、Cocoa アプリでこのクラスを作成する必要があります。MyLookupCommand
サブクラスであるクラスNSScriptCommand
.h
#import <Foundation/Foundation.h>
@interface MyLookupCommand : NSScriptCommand
@end
.m
#import "MyLookupCommand.h"
@implementation MyLookupCommand
-(id)performDefaultImplementation {
// get the arguments
NSDictionary *args = [self evaluatedArguments];
NSString *stringToSearch = @"";
if(args.count)
{
stringToSearch = [args valueForKey:@""];
}
else
{
// error
[self setScriptErrorNumber:-50];
[self setScriptErrorString:@"Parameter Error......."];
}
// Implement your code logic
[[NSNotificationCenter defaultCenter] postNotificationName:@"AppShouldLookupStringNotification" object:stringToSearch];
return [NSString stringWithFormat:@"result: %@", [NSDate date]];
}
@end
そして、これが Applescript から通信をキャプチャする方法です。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[textbox1 setStringValue:[NSString stringWithFormat:@"%05d", 1]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(getValueFromScript:)
name:@"AppShouldLookupStringNotification"
object:nil];
}
-(void)getValueFromScript:(NSNotification *)notification
{
[yourTextbox setStringValue:[NSString stringWithFormat:@"from notification center %@", notification.object]];
}
次のステップでは、Cocoa アプリとの間でコマンドを取得/設定するための Applescript が必要です。
//In SDEF file we declared return type as array, here we created one.
set groceryList to {"eggs", "milk", "bread"} //the variable which you want to send to your app.
//Scripting language is pretty straight forward. If "named" window exists invoke the command and send return type to your Cocoa app.
tell application "Finder"
activate
if ((count of windows) > 0) then
if name of front window is "YOUR_DESIRED_FINDER_WINDOW_NAME" then
tell application "System Events"
set running_apps to every application process's name
if running_apps does not contain "YOUR_COCOA_APP_NAME" then
tell application "AppleScript Editor" to activate
end if
end tell
tell application "AppleScript Editor"
if it is running then
tell application "AppleScript Editor"
myFirstCommand groceryList //Updated this line.
end tell
end if
end tell
end if
end if
end tell
もちろん、Cocoa アプリからも Applescript アプレットを呼び出す必要があります。cocoa AppからApplescriptを呼び出す方法-regulus6633の回答をご覧ください