gpt4 book ai didi

function - AppleScript语法错误

转载 作者:行者123 更新时间:2023-12-03 08:05:00 24 4
gpt4 key购买 nike

我试图使用AppleScript从Mac应用程序Things中输出待办事项列表。

但是我收到语法错误:
预期的表达,但找到“to”。

由于Things使用名称“to dos”而AppleScript不喜欢此名称,因为to是保留关键字。如果重复代码直接在tell语句内部而不在函数处理程序中,则它可以正常工作。

有没有办法解决?

set output to ""

on getTodos(listName)
repeat with todo in to dos of list listName
set todoName to the name of todo
set output to output & todoName
end repeat
end getTodos

tell application "Things"
getTodos("Inbox")
getTodos("Today")
end tell

这样有可能吗?
还有更好的方法吗?

最佳答案

当然,这很容易做到。问题在于,在tell application "Things" ... end tell块之外,AppleScript不知道其中有什么特别的东西,甚至都看不到。然后,您需要做的就是在tell中移动on getTodos(listName) ... end getTodos块:

on getTodos(listName)
tell application "Things"
repeat with todo in to dos of list "Inbox"
set todoName to the name of todo
set output to output & todoName
end repeat
end tell
end getTodos

您也许还可以将 tell替换为 using terms from;我认为应该可以。另外,您永远不会使用 listName -您是要用 "Inbox"替换 listName吗?

但是,您应该能够用单行替换 getTodos
on getTodos(listName)
tell application "Things" to get the name of the to dos of list listName
end getTodos

这种快捷方式是AppleScript擅长的事情之一。另外,请注意,此新版本不会修改 output,而只会返回列表;无论如何,我认为这是一个更好的决定,但是您始终可以执行 set output to output & ...

关于function - AppleScript语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4217714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com