微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

applescript元素,类和对象

如何解决applescript元素,类和对象

| 我正在编写一个applescript,以自动化Aperture中一些繁琐的工作,而且我真不该花时间了解该语言的某些特殊性。特别是,我在处理集合(列表和元素)时确实非常困难。我对包含集合并将对象应用于集合中的元素的对象说明符感到困惑。而且,我对对象说明符中的奇怪差异感到困惑,这些差异在类中按对象类引用对象元素时似乎表现不同,但让我向您展示。 这是脚本的开头。
prop Movies : {}

tell Application \"Aperture\"
     set Movies to every image version whose name of every keywords contains \"Movie\"
end tell

length of Movies   -- result => 601
Aperture中的
application
对象包含
image version
s的元素集合。 “ 2”个对象包含“ 4”个元素的集合。 “ 4”是具有“ 6”和“ 7”属性的对象/列表。 因此,全局脚本属性“ 8”现在包含Aperture库中实际上是视频的所有“ 2”对象。现在,当我尝试执行此操作时:
repeat with movie in Movies
    log (\"Movie name is \'\" & name of movie & \"\'.\")
    log (\"  the class of this object is \'\" & class of movie & \"\'.\")
end
预期的输出是:
Movie name is \'MOV03510.MPG\'.
  the class of this object is \'image version\'.
Movie name is \'MOV00945\'.
  the class of this object is \'image version\'.
Movie name is \'MOV03228.MPG\'.
  the class of this object is \'image version\'.
Movie name is \'MOV02448\'.
  the class of this object is \'image version\'.
...
但是,我对如何访问那些ѭ2elements中的element集合感到困惑。当我这样做时:
repeat with movie in Movies

    log (\"Movie name is \'\" & name of movie & \"\'.\")
    log (\"  the class of this object is \'\" & class of movie & \"\'.\")
    set kwnamelist to name of every keyword in movie
    if kwnamelist contains \"Movie\"
       log (\"    Yes,\'\" & name of movie & \"\' is indeed a video.\")
    end if
end
给我
find_videos.applescript:1089:1096: script error: Expected class name but found identifier. (-2741)
在我看来,该错误听起来像applescript被对象说明符ѭ15所混淆。但是,我对此感到困惑的原因是,如果我编写以下代码
tell Application \"Aperture\"
    repeat with imageind from 1 to 1000
        set img to item imageind of image versions
        tell me to log (\"Image name is \'\" & name of img & \"\'.\")
        tell me to log (\"  the class of this object is \'\" & class of img & \"\'.\")
        set kwnamelist to name of every keyword in img
        if kwnamelist contains \"Movie\" 
            tell me to log (\"    \'\" & name of img & \"\' is actually a video!\")
        end if
    end
end tell
然后我得到预期的输出
...
Image name is \'DSC_4650\'.
  the class of this object is \'image version\'.
Image name is \'104-0487_IMG\'.
  the class of this object is \'image version\'.
Image name is \'MOV02978.MPG\'.
  the class of this object is \'image version\'.
    \'MOV02978.MPG\' is actually a video!
Image name is \'108-0833_IMG\'.
  the class of this object is \'image version\'.

...
谁能告诉我对象说明符怎么了?为什么当
image version
一个上下文中但我不能在另一个上下文中时,我本质上可以将ѭ18应用于
every keyword in img
?这里有我想念的东西吗?
keyword
类是否在Aperture
application
对象的内部?如果是这种情况,我该如何指定类似ѭ23的内容? 更新: 我已经解决了这个特殊问题,但是如果有人可以确切解释为什么会解决,我将非常感激。我这样做:
tell Application \"Aperture\"
    repeat with movie in Movies
        tell me to log (\"Movie name is \'\" & name of movie & \"\'.\")
        tell me to log (\"  the class of this object is \'\" & class of movie & \"\'.\")
        set kwnamelist to name of every keyword in movie
        if kwnamelist contains \"Movie\"
            tell me to log (\"    Yes,\'\" & name of movie & \"\' is indeed a video.\")
        end if
    end
end tell
给出预期的输出
...
Movie name is \'IMG_0359\'.
  the class of this object is \'image version\'.
    Yes,\'IMG_0359\' is indeed a video.
Movie name is \'MOV02921.MPG\'.
  the class of this object is \'image version\'.
    Yes,\'MOV02921.MPG\' is indeed a video.
Movie name is \'MOV02249\'.
  the class of this object is \'image version\'.
    Yes,\'MOV02249\' is indeed a video.
...
似乎这里有一个非常特殊的范围问题。有人可以向我解释在这个新版本中
keyword
对象的范围如何,但是在我们不在
tell
块中的先前版本中超出范围吗?我以为
tell
块仅用于直接命令而没有直接参数?他们也确定类型范围吗?还是在对象说明符的构造/执行中的某处隐藏了依赖于发送至“ 29”对象的命令?     

解决方法

如果我正确理解了您问题的核心-因为您已经解决了实际问题,因此请谨慎地取消引用,这对于applescripters来说有点陈旧了-您必须仅在相关的tell块内使用术语,因此如果您的应用程序(Aperture)提供术语“关键字”,除非您位于
tell application \"Aperture\"
区块内,否则您不能引用“关键字”。 或如果出于某种原因您想使用给定应用程序中的术语而不使用tell块,则可以像这样包装代码:
using terms from application \"Aperture\"
  -- blah blah about \'keyword\' and other Aperture terminology
end using terms from
    ,不幸的是,Applescript很有趣,并且经常碰碰运气。在“ 32”的情况下,项目是对内容的引用,而不是内容本身。通常,AppleScript会为您取消引用,但并非总是如此。通常,我总是使用
repeat with x from 1 to count
方法来避免此问题。     ,关于脚本编写Aperture关键字 Aperture 3中的关键字脚本非常不直观。这是我学到的: 关键字的“ 7”是一个字符串,其路径是从关键字名称到其顶级父级的路径,每个父级的名称前都有一个制表符。
parents
属性的值只是不带名称的id,如果关键字不在顶层,则名称后面的选项卡。 关键字即使值相同也不会相等。其实
keyword 1 of animage != keyword 1 of anImage
如果图像的父代不同,则它们可能具有多个具有相同名称的关键字。但是,该名称只会在显示图像元数据的任何位置出现一次。 在名称为
aName
且名称为
theParents
的父母中向
anImage
添加关键字的方式为
tell anImage to make new keyword with properties {name:aName,parents:theParents,id:aName&tab&theParents}
有关更完整的说明以及添加和删除处理程序,请参见此处。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。