Path 如何指定要使用Applescript处理的文件和文件夹集合?

Path 如何指定要使用Applescript处理的文件和文件夹集合?,path,applescript,filenames,adobe-illustrator,Path,Applescript,Filenames,Adobe Illustrator,我对AppleScript不是很熟练,对命名和枚举文件和路径的各种方法完全感到困惑。根据我找到的文档和示例,我已经尝试了我所能做的一切,但是我遇到了我不理解的错误,或者脚本什么都做不了(我希望如此) 我认为,我的任务相当简单。我试图提供一个脚本,我发现它可以执行我需要使用适当参数执行的大部分工作,所有这些参数都是路径或文件名: on open theFiles -- Assume dropped files are are in the same folder -- Call S

我对AppleScript不是很熟练,对命名和枚举文件和路径的各种方法完全感到困惑。根据我找到的文档和示例,我已经尝试了我所能做的一切,但是我遇到了我不理解的错误,或者脚本什么都做不了(我希望如此)

我认为,我的任务相当简单。我试图提供一个脚本,我发现它可以执行我需要使用适当参数执行的大部分工作,所有这些参数都是路径或文件名:

on open theFiles
    -- Assume dropped files are are in the same folder
    -- Call SaveFilesAsSVG to create svg versions of each dropped file next to the originals in the same folder
end open

on run
    -- Ask for a destination folder with a defined relative path as the default
    -- Ask for a source folder with a defined relative path as a default
    -- Call SaveFilesAsSVG to create an svg version of each file with a defined extension found in the source folder in the destination folder
end run
我面临的挑战是以(第182页)所期望的形式生成论点:


在编写我的
open
run
处理程序时,如有任何帮助,我们将不胜感激

您可以尝试以下方法:

    on open droppedItem
    -- Assume dropped files are are in the same folder
    -- Call SaveFilesAsSVG to create svg versions of each dropped file next to the originals in the same folder
    set droppedItem to first item of droppedItem
    tell application "System Events" to kind of droppedItem = "Folder"
    if the result then
        tell application "System Events" to set myFileList to files of droppedItem whose visible is true
        SaveFilesAsSVG(myFileList, droppedItem's POSIX path, droppedItem)
    end if
end open


on run
    -- Ask for a destination folder with a defined relative path as the default
    set mydestFolder to (choose folder with prompt "Select destination folder")

    -- Ask for a source folder with a defined relative path as a default
    set myFilePath to (choose folder with prompt "Select source folder")

    -- Create fileList
    tell application "System Events" to set myFileList to files of myFilePath whose visible is true

    -- Call SaveFilesAsSVG to create an svg version of each file with a defined extension found in the source folder in the destination folder
    SaveFilesAsSVG(myFileList, myFilePath's POSIX path, mydestFolder)
end run


on SaveFilesAsSVG(fileList, filePath, destFolder)
    set destPath to destFolder as string
    set fileCount to count of fileList
    if fileCount > 0 then
        repeat with i from 1 to fileCount
            tell application "System Events" to set fileName to (item i of fileList)'s name
            set fileNameBase to getBaseName(item i of fileList)

            set fullPath to filePath & fileName
            set newFilePath to destPath & fileNameBase & ".svg"
            tell application "Adobe Illustrator"
                open POSIX file fullPath as alias without dialogs
                export current document to file newFilePath as SVG ¬
                    with options {class:SVG export options ¬
                    , embed raster images:true}
                close current document saving no
            end tell
        end repeat
    end if
end SaveFilesAsSVG


on getBaseName(myFile)
    tell application "System Events" to set {fileName, fileExt} to {name, name extension} of myFile
    return text 1 thru ((get offset of "." & fileExt in fileName) - 1) of fileName
end getBaseName

谢谢这是一个很大的帮助,但是我在删除和运行时都会得到“无法从“.DS_Store.”的0中获取文本1”。此外:我希望能够删除多个文件(而不是文件夹),并在
运行
案例中筛选文件扩展名。
    on open droppedItem
    -- Assume dropped files are are in the same folder
    -- Call SaveFilesAsSVG to create svg versions of each dropped file next to the originals in the same folder
    set droppedItem to first item of droppedItem
    tell application "System Events" to kind of droppedItem = "Folder"
    if the result then
        tell application "System Events" to set myFileList to files of droppedItem whose visible is true
        SaveFilesAsSVG(myFileList, droppedItem's POSIX path, droppedItem)
    end if
end open


on run
    -- Ask for a destination folder with a defined relative path as the default
    set mydestFolder to (choose folder with prompt "Select destination folder")

    -- Ask for a source folder with a defined relative path as a default
    set myFilePath to (choose folder with prompt "Select source folder")

    -- Create fileList
    tell application "System Events" to set myFileList to files of myFilePath whose visible is true

    -- Call SaveFilesAsSVG to create an svg version of each file with a defined extension found in the source folder in the destination folder
    SaveFilesAsSVG(myFileList, myFilePath's POSIX path, mydestFolder)
end run


on SaveFilesAsSVG(fileList, filePath, destFolder)
    set destPath to destFolder as string
    set fileCount to count of fileList
    if fileCount > 0 then
        repeat with i from 1 to fileCount
            tell application "System Events" to set fileName to (item i of fileList)'s name
            set fileNameBase to getBaseName(item i of fileList)

            set fullPath to filePath & fileName
            set newFilePath to destPath & fileNameBase & ".svg"
            tell application "Adobe Illustrator"
                open POSIX file fullPath as alias without dialogs
                export current document to file newFilePath as SVG ¬
                    with options {class:SVG export options ¬
                    , embed raster images:true}
                close current document saving no
            end tell
        end repeat
    end if
end SaveFilesAsSVG


on getBaseName(myFile)
    tell application "System Events" to set {fileName, fileExt} to {name, name extension} of myFile
    return text 1 thru ((get offset of "." & fileExt in fileName) - 1) of fileName
end getBaseName