使用Applescript打开指定文件夹下的文件
假设我有一堆具有类似子路径的文件夹:使用Applescript打开指定文件夹下的文件,applescript,filepath,Applescript,Filepath,假设我有一堆具有类似子路径的文件夹: Folder 1 Do Re Mi <Files> Folder 2 Do Re Mi <Different Files> 文件夹1 做 重新 惯性矩 文件夹2 做 重新 惯性矩 我知道我可以使用告诉application Finder打开“Macintosh HD:Users:…打开文件夹。是否有办法将弹出窗口排队,以选择我要输入的文件夹1或文件夹2
Folder 1
Do
Re
Mi
<Files>
Folder 2
Do
Re
Mi
<Different Files>
文件夹1
做
重新
惯性矩
文件夹2
做
重新
惯性矩
我知道我可以使用告诉application Finder打开“Macintosh HD:Users:…
打开文件夹。是否有办法将弹出窗口排队,以选择我要输入的文件夹1或文件夹2中的哪一个,然后将其输入上述命令?例如,如果我选择文件夹1
,它将转到…文件夹1/Do/Re/Mi
,而如果我选择文件夹2
,它将转到…文件夹2/Do/Re/Mi
我尝试过的一件事是将do shell script
与concatenate相结合,以获得do shell script“open”&变量&“/do/Re/Mi/”
,但是如果文件名不止一个单词,代码就会失败。- 设置基本文件夹
- 检索基本文件夹的所有文件夹名称
- 创建一个列表
- 选择一个项目
- 连接路径并打开文件夹
baseFolder
设置为文件夹1
和文件夹2
的父文件夹的别名)
您可以通过扭曲引号中的路径来修复
do shell脚本的错误:do shell脚本“open\”“&variable&/do/Re/Mi/\”“
?
set baseFolder to path to home folder
set folderList to {}
tell application "Finder" to set allFolders to name of folders of baseFolder
repeat with i from 1 to (count allFolders)
set end of folderList to (i as text) & space & item i of allFolders
end repeat
set chosenItem to choose from list folderList
if chosenItem is false then return
set chosenIndex to word 1 of item 1 of chosenItem
set selectedFolder to item chosenIndex of allFolders
set destinationFolder to (baseFolder as text) & selectedFolder & ":Do:Re:Mi:"
tell application "Finder"
if exists folder destinationFolder then
open folder destinationFolder
else
display dialog "Sorry, the folder does not exist"
end if
end tell