Я пытаюсь добавить тривиальную поддержку AppleScript в приложение Какао.Приложение периодически выполняет проверку, и я просто хочу, чтобы я мог сказать ему, чтобы она выполнялась по требованию.
Я пытаюсь следовать примеру SimpleScriptingVerbs Apple.
У меня есть подкласс NSScriptCommand
следующим образом:
Заголовок:
#import <Cocoa/Cocoa.h>
@interface rdrNotifierUpdateCommand : NSScriptCommand {
}
-(id)performDefaultImplementation;
@end
Реализация:
#import "rdrNotifierUpdateCommand.h"
#import "rdrNotifierAppDelegate.h"
@implementation rdrNotifierUpdateCommand
-(id)performDefaultImplementation {
NSLog(@"Works at last");
[((rdrNotifierAppDelegate *)[[NSApplication sharedApplication] delegate])
checkForNewItems]; // This just fires the timer
return nil;
}
@end
Мой .sdef
файл выглядит следующим образом (и проблема кажетсячтобы быть там, но я не могу его найти):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>
<suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities.">
<command name="do update" code="rdrNUpdt" description="Check for new items">
<cocoa class="rdrNotifierUpdateCommand"/>
</command>
</suite>
</dictionary>
Info.plist
настроен соответствующим образом.
Но, когда я пытаюсь запустить следующий скрипт в редакторе AppleScript:
tell application "rdrNotifier"
do update
end tell
Я получаю сообщение об ошибке, что переменная "update" не определена.
Я могу открыть словарь для моего приложения из редактора AppleScript (т.е. он успешно зарегистрирован).
Редактировать: Найдено решение
Проблема действительно была в файле sdef
: я не указывал, что приложение может ответить на команду.Мое окончательное определение выглядит следующим образом (код Obj-C без изменений):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude">
<!-- I have removed the standard suite as the application does not open, print... -->
<suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities.">
<command name="do update" code="rdrNUpdt" description="Check for new items">
<cocoa class="rdrNotifierUpdateCommand"/>
</command>
<class name="application" code="Capp">
<cocoa class="NSApplication"/>
<responds-to name="do update">
<!-- Note you need to specify a method here,
although it is blank -->
<cocoa method=""/>
</responds-to>
</class>
</suite>
</dictionary>
Любые улучшения / советы / критика по-прежнему приветствуются.