【问题标题】:Opening the latest downloaded CSV file with Excel using AppleScript使用 AppleScript 使用 Excel 打开最新下载的 CSV 文件
【发布时间】:2020-07-02 02:57:16
【问题描述】:

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

我一直在尝试找到一些代码并使其适应我的需要,但它不起作用

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

tell application "Finder"   
    open last item of (sort (get files of (path to downloads folder)) by creation date) 
end tell

当我更改为告诉应用程序“excel”时,它会返回错误。

“应为“,”但找到“by”。”

感谢您的帮助!

【问题讨论】:

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

标签: excel macos applescript


【解决方案1】:

Finder 的open 命令有一个using 参数,可让您指定应用程序来打开文件。即,这样编码:

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

【讨论】:

    【解决方案2】:

    您必须将 Finder 项强制转换为文件路径。这个路径引用可以用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多