如何将窗口对象转换为AppleScript中的字符串?
我有一个applescript检索应用程序的窗口ID。 示例以下脚本检索勇敢浏览器的窗口ID。
set urls to {"https://google.com"}
tell application "Brave Browser"
set myNewWindow to make new window
repeat with theURL in urls
tell myNewWindow to open location theURL
end repeat
delay 0.3
log myNewWindow
return class of myNewWindow //comment - returns "window" as a class
end tell
我的目标是将窗口ID转换为字符串,反之亦然。
为什么要转换?
- 我想将窗口ID保存在MacOS上的UserDefaults中。
注意:此AppleScript在MacOS应用中使用。
I've an AppleScript that retrieves window id of an app.
Example following script retrieves the window id of Brave Browser.
set urls to {"https://google.com"}
tell application "Brave Browser"
set myNewWindow to make new window
repeat with theURL in urls
tell myNewWindow to open location theURL
end repeat
delay 0.3
log myNewWindow
return class of myNewWindow //comment - returns "window" as a class
end tell
My goal is it possible to convert the window id to a string and vice-versa.
Why conversion?
- I want to save window id in UserDefaults on macOS.
Note: This AppleScript is used in macOS app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,我很难理解为什么应该将ID保留在默认情况下。因为 theID 变量已经将此值存储在整个脚本中。并且在任何时候,您都可以在脚本后期的一个部分中使用变量关闭窗口。我只能假设一件事:您想在本地打开一个窗口,然后将其从远程计算机上执行的其他脚本关闭。
并在勇敢的浏览器中获取窗口ID很容易:
从其他脚本关闭窗口:
To be honest, it's hard for me to understand why the ID should be kept in defaults. Because theID variable will already store this value throughout the script. And at any time you can close the window using a variable in a later part of the script. I can only assume one thing: you want to open a window locally and then close it from other script executed on a remote machine.
And getting the window ID in Brave Browser as text is easy:
Closing the window from other script: