如何确定变量的数据类型?如何转换为字符串?
我有两个问题...
这是一个非常简单的示例脚本,它会导致错误:
系统事件出现错误:无法将可见 = true 的每个应用程序进程的第 1 项制作为字符串类型。
tell application "System Events"
repeat with appProc in (every application process whose visible is true)
display dialog appProc
end repeat
end tell
1-如何确定变量的数据类型?
这对将来的参考很有帮助,这样我就可以弄清楚我正在处理什么类型的数据类型
2-如何将上述数据类型转换为字符串,以便它在显示对话框中显示?
我尝试添加:
appProc as string
但随后我收到另一个错误:
无法将应用程序“系统事件”的“class pcap”“myapplication”制作为字符串类型。
I have two questions...
Here is a really simple example script which causes an error:
System Events got an error: Can’t make item 1 of every application process whose visible = true into type string.
tell application "System Events"
repeat with appProc in (every application process whose visible is true)
display dialog appProc
end repeat
end tell
1- How do I determine the data type of a variable?
This would be helpful for future reference so I can figure out what kind of data type I am dealing with
2- How do I convert the above data type to a string so it displays with display dialog?
I tried adding:
appProc as string
but then I get another error that says:
Can’t make «class pcap» "myapplication" of application "System Events" into type string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获取数据类型...使用类...
转换为字符串?...尝试“作为文本”或“作为字符串”。它大部分有效。但是,在您的情况下,appProc 有属性(如 Red_menace 提到的),并且您想显示其名称属性...
To get the data type... use class...
Convert to string?... try "as text" or "as string". It mostly works. However in your case appProc has properties (as Red_menace mentioned) and you want to display its name property...