到目前为止,我正在显示文件夹中当前文件的列表。我希望能够从列表中选择其中一个文件并从对话框中重命名,但它似乎不起作用。有什么想法吗?
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 filelist OK button name "Rename" cancel button name "Back" with prompt "Choose a Script to rename" with title "Rename this File")
set updatedInfo to the text returned of (display dialog "What would you like to rename " & returnedInfo & " to?" default answer returnedInfo buttons "Rename" default button 1)
tell application "Finder"
set the name of file ((path to me as text) & "Contents:Resources:Plugins:" & returnedInfo & ".scpt") to updatedInfo & ".scpt"
end tell
非常感谢你的帮助,为一个大项目工作,如果有效的话,这个功能会很棒。
答案 0 :(得分:0)
它不起作用,因为returnedInfo
是一个列表,你必须将它展平:
...
set returnedInfo to (choose from list filelist OK button name "Rename" cancel button name "Back" with prompt "Choose a Script to rename" with title "Rename this File")
if returnedInfo is false then
-- handle if user pressed 'Cancel'
else
set returnedInfo to item 1 of returnedInfo
set updatedInfo to the text returned of (display dialog "What would you like to rename " & returnedInfo & " to?" default answer returnedInfo buttons "Rename" default button 1)
tell application "Finder"
set name of file (scriptLocation & "Plugins:" & returnedInfo & ".scpt") to updatedInfo & ".scpt"
end tell
end if