我的脚本处理音频文件,如果脚本确定存在非音频文件或音频文件格式不同,我希望包含警告。这就是我尝试过的。理想情况下,do shell script
会很好,或者通过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
答案 0 :(得分:1)
您还可以使用系统事件加快速度。
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