使用 AppleScript 打开邮件

发布于 2024-10-18 06:27:36 字数 191 浏览 2 评论 0原文

我想我可以这样做:

tell application "Mail"
activate
end tell

虽然我可以在顶部看到邮件工具栏。它并没有将邮件应用程序带到最前面以使其完全可见。

我的录音机也由于某种原因无法工作,所以我无法用它来找出我需要做什么。

我该怎么做?

I thought I could just do this:

tell application "Mail"
activate
end tell

Although I can see the Mail toolbar at the top. It hasn't brought the mail app to the front to be fully visible.

My recorder doesn't work for some reason too, so I can't use that to find out what I need to do.

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

看轻我的陪伴 2024-10-25 06:27:36

您可能已经关闭了邮件窗口,因此当您激活应用程序时,不会显示任何打开的窗口。因此,您必须自己打开一个。请注意,邮件中的主窗口称为“消息查看器”。试试这个...

AppleScript:

tell application "Mail"
    activate
    if (count of message viewers) is 0 then
        make new message viewer at front
        set selected mailboxes of message viewer 1 to {inbox}
    end if
end tell

JXA:

var Mail = Application("Mail")
Mail.activate()
if (Mail.messageViewers().length === 0) {
  Mail.MessageViewer().make()
  var mv = Mail.messageViewers()[0]
  mv.selectedMailboxes.set(mv.inbox())
}

顺便说一下,录音机在大多数应用程序中都不起作用,所以当我听说它不适用于邮件时,我并不感到惊讶。应用程序作者必须将此功能编码到程序中,而大多数开发人员(包括 Apple)不会这样做。

You probably have closed the mail window so when you activate the application there isn't any open windows to show. As such you have to open one yourself. Note that the main window in mail is called a "message viewer". Try this...

AppleScript:

tell application "Mail"
    activate
    if (count of message viewers) is 0 then
        make new message viewer at front
        set selected mailboxes of message viewer 1 to {inbox}
    end if
end tell

JXA:

var Mail = Application("Mail")
Mail.activate()
if (Mail.messageViewers().length === 0) {
  Mail.MessageViewer().make()
  var mv = Mail.messageViewers()[0]
  mv.selectedMailboxes.set(mv.inbox())
}

By the way, the recorder doesn't work in most applications so I'm not surprised to hear that it doesn't work for Mail. An application author has to code this ability into the program and most developers (including Apple) do not do this.

吐个泡泡 2024-10-25 06:27:36

你正在做的事情应该有效。不知道为什么它不适合你。

What you're doing should work. Not sure why it's not working for you.

2024-10-25 06:27:36

好吧,您随时可以尝试再次激活它。或者,您可以直接告诉 Finder 启动它,看看效果是否更好:

tell application "Finder" to open application file id "com.apple.mail"

Well, you can always try activating it a second time. Alternatively, you can just tell the Finder to launch it and see if that works any better:

tell application "Finder" to open application file id "com.apple.mail"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文