在 Applescript 中引用双字变量?
Referencing Two-Word Variables in Applescript?
我正在尝试从一个名为 "Timing" 的应用程序获取一些数据,该应用程序位于我的本地计算机上,并且 post 将其发送到 URL 以通知网络钩子,来自这将发生一些过程自动化。
According to the Applescript integration with Timing,
有一个 time summary
对象是从我成功执行的命令返回的。当显示为警报时,该数据如下所示:
Can't get |times per project| of {id:5C6CD8C8-357F-4EE7-890C-5946DC03BBB9", overall total:1.18092493622303E+4, times per project:{Maintenance:81.091759443283, Youtube:4820.38001298904, |self improvement effors|:876.930474758148, Homework:2383.20326805115, |(no project)|:3647.64384698868}, overall total without tasks:1.18092493622303E+4, productivity score:0.388005592511, times per project without tasks:{Maintenance:81.091759443283, Youtube:4820.38001298904, |self improvement efforts|:876.930474758148, Homework:2383.20326805115, |(no project)|:3647.64384698868}, class:time summary}.
大家可以看到,(上图)有一个属性叫productivity score
,就是两个字
当尝试从对象中获取此数据点时(我将使用它来通知 webhook:)
set newnewVar to productivity score of newvar
display alert newvar
显然这行不通,因为变量名是两个单词。我试过用引号将名称括起来并用其他字符括起来,但似乎没有任何效果,并且 the documentation for getting specific properties 只有一个单词的变量示例。
这个问题的解决方案是什么?
在 AppleScript 中,user-defined 变量通常不能有空格。通常它们以字母或下划线开头,然后只能包含字母、数字或下划线。如果 user-defined 变量包含在垂直管道中,则它只能包含空格。所以以下所有变量形式都是有效的:alphaUnit
、slideRow3
、_tempItem
、|my variable|
、left_hand_vector
但是,任何创建和使用脚本定义的应用程序或脚本都可以创建具有 multi-word 名称的命令和 classes 以及属性。例如,如果您查看系统事件应用程序,您会看到 Disk-Folder-File 套件有一个名为 disk item
的 class,其属性类似于 creation date
。这样做的原因是这些 multi-word 名称实际上由数字 (four-char) 代码表示:disk item
实际上是 'ditm'
而 creation date
是 'ascd'
.您经常看到这些代码在错误字符串中弹出,如下所示:
"cannot make class ≪ditm≫ into..."
确保您拥有调用字典的范围权限——即在调用脚本字典的应用程序或脚本的 tell
块内——并且 multi-word 名称应该 'just work'.编译后,您会看到它们以紫色突出显示,与未编译文本的红色略有不同。您不需要在垂直管道中包含字典术语;如果这样做,它们将被视为 user-defined 变量并失去其特殊的脚本用途。
我正在尝试从一个名为 "Timing" 的应用程序获取一些数据,该应用程序位于我的本地计算机上,并且 post 将其发送到 URL 以通知网络钩子,来自这将发生一些过程自动化。
According to the Applescript integration with Timing,
有一个 time summary
对象是从我成功执行的命令返回的。当显示为警报时,该数据如下所示:
Can't get |times per project| of {id:5C6CD8C8-357F-4EE7-890C-5946DC03BBB9", overall total:1.18092493622303E+4, times per project:{Maintenance:81.091759443283, Youtube:4820.38001298904, |self improvement effors|:876.930474758148, Homework:2383.20326805115, |(no project)|:3647.64384698868}, overall total without tasks:1.18092493622303E+4, productivity score:0.388005592511, times per project without tasks:{Maintenance:81.091759443283, Youtube:4820.38001298904, |self improvement efforts|:876.930474758148, Homework:2383.20326805115, |(no project)|:3647.64384698868}, class:time summary}.
大家可以看到,(上图)有一个属性叫productivity score
,就是两个字
当尝试从对象中获取此数据点时(我将使用它来通知 webhook:)
set newnewVar to productivity score of newvar
display alert newvar
显然这行不通,因为变量名是两个单词。我试过用引号将名称括起来并用其他字符括起来,但似乎没有任何效果,并且 the documentation for getting specific properties 只有一个单词的变量示例。
这个问题的解决方案是什么?
在 AppleScript 中,user-defined 变量通常不能有空格。通常它们以字母或下划线开头,然后只能包含字母、数字或下划线。如果 user-defined 变量包含在垂直管道中,则它只能包含空格。所以以下所有变量形式都是有效的:alphaUnit
、slideRow3
、_tempItem
、|my variable|
、left_hand_vector
但是,任何创建和使用脚本定义的应用程序或脚本都可以创建具有 multi-word 名称的命令和 classes 以及属性。例如,如果您查看系统事件应用程序,您会看到 Disk-Folder-File 套件有一个名为 disk item
的 class,其属性类似于 creation date
。这样做的原因是这些 multi-word 名称实际上由数字 (four-char) 代码表示:disk item
实际上是 'ditm'
而 creation date
是 'ascd'
.您经常看到这些代码在错误字符串中弹出,如下所示:
"cannot make class ≪ditm≫ into..."
确保您拥有调用字典的范围权限——即在调用脚本字典的应用程序或脚本的 tell
块内——并且 multi-word 名称应该 'just work'.编译后,您会看到它们以紫色突出显示,与未编译文本的红色略有不同。您不需要在垂直管道中包含字典术语;如果这样做,它们将被视为 user-defined 变量并失去其特殊的脚本用途。