Applescript 下载&打开链接

发布于 2024-08-13 04:16:25 字数 690 浏览 1 评论 0原文

我在 Apple Mail 中设置了一条规则来运行“下载并打开链接”applescript。我希望这个脚本下载邮件消息中的网址,下载后应该打开该文件。

不知道如何开始。这是不起作用的代码:

using terms from application "Mail"
    on perform mail action with messages newMessages
        repeat with newMessage in newMessages

            tell application "Mail"
                set contentLink to (content of newMessage)
            end tell

            set the destination_file to ("/Users/thomas/Downloads/file")

            tell application "URL Access Scripting"
                download contentLink to destination_file replacing yes
            end tell


        end repeat
    end perform mail action with messages
end using terms from

I've set a rule in Apple Mail to run a "Download & Open link" applescript. I would like this script to download the url in the mail message and after downloading it should open the file.

No idea how to start on this. Here's the code that isn't working:

using terms from application "Mail"
    on perform mail action with messages newMessages
        repeat with newMessage in newMessages

            tell application "Mail"
                set contentLink to (content of newMessage)
            end tell

            set the destination_file to ("/Users/thomas/Downloads/file")

            tell application "URL Access Scripting"
                download contentLink to destination_file replacing yes
            end tell


        end repeat
    end perform mail action with messages
end using terms from

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

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

发布评论

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

评论(1

浪菊怪哟 2024-08-20 04:16:25

您正在尝试将链接下载到字符串中,除非您将字符串强制转换为别名,否则这是不可能的。您可以通过以下两种方式之一执行此操作。

  1. 强制变量 destination_file 初始化为别名...

    将destination_file设置为“/Users/thomas/Downloads/file/”作为POSIX文件作为别名
    

  2. 在下载链接时强制执行该变量...

    下载内容链接到destination_file作为POSIX文件作为别名替换yes
    

完成此操作后,您现在需要做的就是导航到下载文件的文件夹并将其打开。

例子:

tell application "Finder" to open "Macintosh HD:Users:Anonymous:Downloads:example.txt" as alias

You're trying to download the link into a string, which is impossible unless you coerce the string into an alias. You could do this one of two ways.

  1. Coerce the variable destination_file as it's initialized into an alias...

    set the destination_file to "/Users/thomas/Downloads/file/" as POSIX file as alias
    
  2. Coerce the variable when you're downloading the link...

    download contentLink to destination_file as POSIX file as alias replacing yes
    

Once you've done that, all you need to do now is navigate to the folder where you downloaded the file and open it.

Example:

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