【问题标题】:Converting a Swift string which contains multiple file paths to an AppleScript list将包含多个文件路径的 Swift 字符串转换为 AppleScript 列表
【发布时间】:2017-05-20 16:27:18
【问题描述】:

假设有两个文件路径:

/Users/xxx/Desktop/AWP2014.epub

/Users/xxx/Desktop/algorithms.epub

然后用下面的代码组成一个字符串:

var pathList = ""
for (index,path) in lastFilePaths.enumerated()
{
    guard let path = path else {continue}
    pathList += path
    if index != lastFilePaths.endIndex-1
    {
        pathList += ","
    }
}

现在如何将此字符串转换为 applescript 的文件列表?所以我可以像这样使用这个列表:

tell application "Finder"
set myFilesList to listConvertFromSwiftString
move myFilesList to myDestinFolder

【问题讨论】:

    标签: swift macos applescript finder


    【解决方案1】:

    如果您使用 Swift 进行编码,您究竟为什么要通过 AppleScript 使用 Finder 而不是 FileManager.moveItem(atPath:toPath:) 来移动文件?

    【讨论】:

    • 我的情况比较特殊,我只是想让这个功能由 Finder 执行,而不是由我的应用程序执行。 @foo
    【解决方案2】:

    找到解决方案:

        let scriptString = 
            "tell application \"Finder\"\n" +
            "set theList to \(String(describing: pathList)) as list\n" +
            "set myNewList to {}\n" +
            "repeat with pathItem in theList\n" +
            "set newPath to pathItem\n" +
            "set end of myNewList to (newPath as POSIX file)\n" +
            "end repeat\n" +
            "end tell\n"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-28
      • 2015-04-16
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 2022-10-23
      • 2020-04-14
      相关资源
      最近更新 更多