开发者

Applescript download & open link

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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜