AppleScript:如何获取文件夹中的文件文件列表并从该列表中删除扩展名

时间:2016-05-18 12:35:00

标签: macos applescript

我有这个代码正常工作,以获取名为Plugins的文件夹中的脚本列表。但是,我想在没有显示文件扩展名的情况下在选择列表中显示该列表。

set scriptLocation to alias ((path to me as text) & "Contents:Resources")
tell application "Finder"

set filelist to name of every file in folder "Plugins" of scriptLocation whose name extension is "scpt"
end tell
set {TID, text item delimiters} to {text item delimiters, return}
set text item delimiters to TID



set returnedInfo to (choose from list {"Menu"} & "" & filelist)

代码非常大,我只是放入了一部分来处理获取文件列表并将其显示为从列表中选择。

1 个答案:

答案 0 :(得分:0)

您需要重复循环

set scriptLocation to alias ((path to me as text) & "Contents:Resources:")

tell application "System Events"
    set filelist to name of every file in folder "Plugins" of scriptLocation whose name extension is "scpt"
end tell
repeat with aFile in filelist
    set contents of aFile to text 1 thru -6 of aFile
end repeat

set returnedInfo to (choose from list {"Menu"} & "" & filelist)