使用AppleScript使用Excel打开最新下载的CSV文件

使用AppleScript使用Excel打开最新下载的CSV文件,excel,macos,applescript,Excel,Macos,Applescript,我需要找到一种方法,使用excel自动打开上次下载的CSV文件 我一直在试图找到一些代码,并使其适应我的需要,但它不会工作 下面的代码将按预期打开带有数字的最新文件。我无法更改CSV文件默认使用的数字 tell application "Finder" open last item of (sort (get files of (path to downloads folder)) by creation date) end tell 当我改为告诉应用程序“excel”时,它返

我需要找到一种方法,使用excel自动打开上次下载的CSV文件

我一直在试图找到一些代码,并使其适应我的需要,但它不会工作

下面的代码将按预期打开带有数字的最新文件。我无法更改CSV文件默认使用的数字

tell application "Finder"   
    open last item of (sort (get files of (path to downloads folder)) by creation date) 
end tell
当我改为告诉应用程序“excel”时,它返回一个错误

“应为”“但由”“找到”。”


谢谢你的帮助

必须将查找程序项强制为文件路径。可以使用Excel打开此路径引用

tell application "Finder"
    set latestFile to last item of (sort (get files of (path to downloads folder)) by creation date) as text
end tell
tell application "Microsoft Excel" to open latestFile

必须将查找程序项强制为文件路径。可以使用Excel打开此路径引用

tell application "Finder"
    set latestFile to last item of (sort (get files of (path to downloads folder)) by creation date) as text
end tell
tell application "Microsoft Excel" to open latestFile

查找器的
open
命令有一个
using
参数,用于指定打开文件的应用程序。i、 例如,按以下方式编码:

tell application "Finder"
    set theFolder to folder (path to downloads folder)
    set latestFile to last item of (sort (files of theFolder) by creation date)
    open latestFile using (path to application "Microsoft Excel")
end tell

查找器的
open
命令有一个
using
参数,用于指定打开文件的应用程序。i、 例如,按以下方式编码:

tell application "Finder"
    set theFolder to folder (path to downloads folder)
    set latestFile to last item of (sort (files of theFolder) by creation date)
    open latestFile using (path to application "Microsoft Excel")
end tell

请记住,
创建日期
不一定是在系统上创建文件的日期,因此,不一定等于最近下载的文件。有一个名为
kMDItemDateAdded
的Finder元数据标记,它保存文件添加到当前所在文件夹的日期。 因此,最近下载的文件(到您的
~/Downloads
文件夹将具有最新的
kMDItemDateAdded
日期值,直到文件被移动到另一个文件夹,或其他文件被添加到下载文件夹。请记住
创建日期不一定是在您的系统上创建文件的日期,因此并不等同于必须是最近下载的文件。有一个名为
kMDItemDateAdded
的Finder元数据标记,它保存文件添加到当前所在文件夹的日期。 因此,最新下载的文件(到您的
~/Downloads
文件夹中)将具有最新的
kMDItemDateAdded
日期值,直到该文件被移动到另一个文件夹中,或者其他一些文件被添加到下载文件夹中。