如何确定变量的数据类型?如何转换为字符串?

发布于 2024-12-23 09:44:49 字数 560 浏览 4 评论 0原文

我有两个问题...

这是一个非常简单的示例脚本,它会导致错误:

系统事件出现错误:无法将可见 = 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逐鹿 2024-12-30 09:44:49

要获取数据类型...使用类...

set a to "some text variable"
return class of a

转换为字符串?...尝试“作为文本”或“作为字符串”。它大部分有效。但是,在您的情况下,appProc 有属性(如 Red_menace 提到的),并且您想显示其名称属性...

display dialog (name of appProc)

To get the data type... use class...

set a to "some text variable"
return class of a

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...

display dialog (name of appProc)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文