Пытается открыть файл по пути Objective-C в ApplescriptObjC

Я опытный программист какао и новичок в Applescript. Мне нужно запрограммировать генератор отчетов на базе Microsoft. Я начал с моста Applescript и в основном ударил по стене Word. Я сейчас пытаюсь с ApplescriptObjC, и я борюсь, как ад.

Я даже застрял в глупом шаге открытия файла, когда его путь сообщается методом, написанным в Objective-C. Код класса Objective-C очень прост (как надуманный пример):

@implementation Reporter
- (NSString *)templatePath:(NSString *)fileName
{
    NSString *fullPath = [self.currentDirectory stringByAppendingPathComponent:fileName];
    return  fullPath;
}
@end

Примечание: текущий каталог не является каталогом встроенного приложения. Вот одна из моих попыток использовать его:

on createReport()
    set my myReporter to Reporter's alloc()'s init()
    set WordApp to the application "Microsoft Word"
    set FinderApp to the application "Finder"
    set theWordTemplatePath to myReporter's templatePath:"Rapport.docx"
    set theWordTemplatePath to theWordTemplatePath as text
    tell FinderApp to open POSIX file theWordTemplatePath
end createReport

Этот получает эту ошибку:

*** -[CMDAppDelegate applicationWillFinishLaunching:]: Finder got an error: Can’t make «class ocid» id «data optr0000000080B00E0080600000» into type integer. (error -1700)

Я пробовал много вариантов, и, несмотря на многочасовые попытки, я все еще не могу, чтобы Word открыл мой файл.

Что я делаю неправильно?

1 ответ

Решение

По некоторым причинам формы как POSIX file x а также alias y часто приходится переписывать как pPath as POSIX file а также hfsPath as alias в ASObjC.

Попробуй это:

set my myReporter to Reporter's alloc()'s init()
set theWordTemplatePath to myReporter's templatePath:"Rapport.docx"
set tPath to ((theWordTemplatePath as text) as POSIX file) as alias
tell application "Microsoft Word" to open tPath
Другие вопросы по тегам