Macos 你能实现OSX';s Finder从shell脚本下载进度条?

Macos 你能实现OSX';s Finder从shell脚本下载进度条?,macos,scripting,finder,xattr,Macos,Scripting,Finder,Xattr,起初,我认为这可能是扩展属性的一些变体,可以使用xattr命令行工具修改这些属性。但是,我已经进行了几个测试,在这种模式下,文件似乎没有任何特殊属性 这是可以从命令行访问的,还是只能从某些cocoa api中访问?AFAIK,这都是通过Nprogress类(一个cocoa api)实现的,因此仅从shell脚本实现是非常不可能的: 以下是Chrome是如何实现的(可能有更新的代码): 如果您不介意使用swift编写脚本: #!/usr/bin/env swift import Foundat

起初,我认为这可能是扩展属性的一些变体,可以使用xattr命令行工具修改这些属性。但是,我已经进行了几个测试,在这种模式下,文件似乎没有任何特殊属性


这是可以从命令行访问的,还是只能从某些cocoa api中访问?

AFAIK,这都是通过Nprogress类(一个cocoa api)实现的,因此仅从shell脚本实现是非常不可能的:

以下是Chrome是如何实现的(可能有更新的代码):

如果您不介意使用swift编写脚本:

#!/usr/bin/env swift

import Foundation

let path = ProcessInfo.processInfo.environment["HOME"]! + "/Downloads/a.txt"
FileManager.default.createFile(atPath: path, contents: nil, attributes: [:])
let url = URL(fileURLWithPath: path)

let progress = Progress(parent: nil, userInfo: [
    ProgressUserInfoKey.fileOperationKindKey: Progress.FileOperationKind.downloading,
    ProgressUserInfoKey.fileURLKey: url,
])

progress.kind = .file
progress.isPausable = false
progress.isCancellable = false
progress.totalUnitCount = 5
progress.publish()

while (progress.completedUnitCount < progress.totalUnitCount) {
    sleep(1)
    progress.completedUnitCount += 1
    NSLog("progress %d", progress.completedUnitCount)
}

NSLog("Finished")
#/usr/bin/env swift
进口基金会
让path=ProcessInfo.ProcessInfo.environment[“HOME”]!+“/Downloads/a.txt”
FileManager.default.createFile(atPath:path,contents:nil,attributes:[:])
让url=url(fileURLWithPath:path)
让进度=进度(父项:nil,用户信息:[
ProgressUserInfoKey.fileOperationKindKey:Progress.FileOperationKind.downloading,
ProgressUserInfoKey.fileURLKey:url,
])
progress.kind=.file
progress.isPausable=false
progress.isCancellable=false
progress.totalUnitCount=5
progress.publish()
while(progress.completedUnitCount
(Apple Swift版本4.1.2,Xcode 9.4)


多亏了

老实说,我从来没想到这个问题会得到回答。非常棒。