Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix Applescript确定文件类型,如果不相同,则给出错误_Unix_Terminal_Applescript_Osx Mavericks - Fatal编程技术网

Unix Applescript确定文件类型,如果不相同,则给出错误

Unix Applescript确定文件类型,如果不相同,则给出错误,unix,terminal,applescript,osx-mavericks,Unix,Terminal,Applescript,Osx Mavericks,我的脚本处理音频文件,如果脚本确定存在非音频文件或音频文件的格式不完全相同,我希望包括一个警告。这就是我尝试过的。理想情况下,do shell脚本会很好,或者通过Finder绕过文件夹的get项,因为这会大大降低过程的速度 -- Get location of the files display dialog "Be sure that you have selected the folder in the front Finder window that you want to

我的脚本处理音频文件,如果脚本确定存在非音频文件或音频文件的格式不完全相同,我希望包括一个警告。这就是我尝试过的。理想情况下,
do shell脚本
会很好,或者通过Finder绕过文件夹的get项,因为这会大大降低过程的速度

    -- Get location of the files
    display dialog "Be sure that you have selected the folder in the front Finder window that you want to process!" buttons {"OK"} default button 1
    tell application "Finder" to set thisDir to (target of Finder window 1) as string
    set theDir to quoted form of POSIX path of thisDir
    set theFileCount to (do shell script "ls -1 " & theDir & " | wc -l") as integer
    -- Select the files in the locations & check that they are the same.
    tell application "Finder" to select (every file of target of front window whose name contains ".mp3" or name contains ".wav" or name contains ".aif")
    tell application "Finder" to set thefiles to (every file of target of front window whose name contains ".mp3" or name contains ".wav" or name contains ".aif")
    set the firstfileExt to the name extension of item 1 of thefiles
    if theFileCount is greater than 1 then
        set theFileCounter to 2
        repeat theFileCount times
            set the otherfileExt to the name extension of item theFileCounter of thefiles
            if firstfileExt is otherfileExt then
                -- do nothing
            else
                display dialog "the audio files are not all the same format" buttons {"OK"} default button 1
                return
            end if
        end repeat
    end if

您还可以使用系统事件来加快速度

tell application "Finder" to set thisDir to (target of Finder window 1) as alias
tell application "System Events"
    set targetFiles to name extension of files of thisDir whose name extension = "mp3" or name extension = "aif" or name extension = "wav"
    set dupeCheck to {first item of targetFiles}
    repeat with aFile in my targetFiles
        if aFile is not in dupeCheck then
            display dialog "the audio files are not all the same format" buttons {"OK"} default button 1
            return
        end if
    end repeat
end tell

谢谢系统事件在我这方面需要更多的关注。