【发布时间】:2012-03-26 01:07:18
【问题描述】:
是否可以在 OSX 10.7 中从 AppleScript 调用 Objective-c 类?
我已经看到了一些针对 Snow Leopard 或更早版本的建议,但似乎都没有。
AppleScript-Obj-C 似乎是一种构建使用 AppleScript 的 GUI 的方法,但我想调用我从脚本编写的类。
以下(不起作用)是我想做的:-
on getJpegComment(photoFile)
set aJpeg to call method "initWithPath" of class "JpegCom" with parameter photoFile (does not work)
return call method "comment" of aJpeg
end getJpegComment
tell application "iPhoto"
tell album "Sale"
set thePhotos to get every photo
end tell
repeat with aPhoto in thePhotos
tell application "iPhoto"
set aPhotoFile to image path of aPhoto
set aComment to my getJpegComment(aPhotoFile)
set comment of aPhoto to aComment
end tell
end repeat
end tell
我开始走这条路是因为链接似乎表明这是可能的。
我可以编写一个名为 AppleScript 的 Objective-c 程序,但这似乎是一个简单的任务。
PS 我有数千张照片,我已经输入了 Windows 的 JPEG COMments,不幸的是 iPhoto 不理解这些。
【问题讨论】:
-
那么你在用applescript-objc吗?
-
"call method" 来自 AppleScript Studio,在 Snow Leopard 中已被弃用。 AppleScriptObjC 除了可以直接调用 Cocoa 类方法外,还可以调用 Objective-C 类,反之亦然——“JpegCom”类是什么?
-
感谢所有评论的人。我开始怀疑你不能从 AppleScript 调用 Objective-C。我确实尝试过使用 Xcode 创建的 AppleScriptObjC 应用程序,但我不想要 GUI - 只是一个简单的脚本。我能找到的所有示例都是 GUI(制作 Objective-C 应用程序要容易得多)。如果我可以使用我的主脚本,并在 AppleScriptObjC 中提供一个处理程序,那将是理想的。
标签: objective-c applescript osx-lion