Applescript 在Finder中选择多个文件
在我的applescript中,我有一个函数,它获取选定的文件并将其路径写入xml文件。如果选择了一个文件夹,我可以创建一个包含文件的列表,并将其发送给我的函数。但是,如果我选择了多个finder项(通过shift键单击),无论是文件还是文件夹,我都无法向函数发送任何内容 这是我从Finder获取文件的部分Applescript 在Finder中选择多个文件,applescript,Applescript,在我的applescript中,我有一个函数,它获取选定的文件并将其路径写入xml文件。如果选择了一个文件夹,我可以创建一个包含文件的列表,并将其发送给我的函数。但是,如果我选择了多个finder项(通过shift键单击),无论是文件还是文件夹,我都无法向函数发送任何内容 这是我从Finder获取文件的部分 tell application "Finder" set myPath to the selection end tell --if multiple files selected i
tell application "Finder"
set myPath to the selection
end tell
--if multiple files selected
if (count of myPath) is greater than 1 then
set fileList to every item of myPath
repeat with i in fileList
if (isDirectory(i)) then
else
myBigLoop(initialSuccess, i, watchFolder)
end if
end repeat
else if (isDirectory(myPath)) then
submitFolder(myPath, watchFolder)
else
set isFolder to false
set initialSuccess to true
myBigLoop(initialSuccess, myPath, watchFolder)
end if
on myBigLoop(initialSuccess, fileList, watchFolder)
repeat with myPath in fileList
if initialSuccess then
tell application "Finder"
set myFilename to myPath as alias
set myPath to the folder of myFilename
set myPath to myPath as string
set myFilename to name of myFilename
display dialog myFilename
end tell
end if --end InitialSuccess
end repeat
end myBigLoop
on isDirectory(someItem) -- someItem is a file reference
set filePosixPath to quoted form of (POSIX path of (someItem as alias))
set fileType to (do shell script "file -b " & filePosixPath)
if fileType ends with "directory" then return true
return false
end isDirectory
on submitFolder(myPath, watchFolder)
set isFolder to true
set initialSuccess to true
set fileList to item 1 of myPath
set fileList to get every file of fileList
set numFiles to count fileList
if numFiles is equal to 0 then
display dialog "There were no files in that folder."
return false
end if
myBigLoop(initialSuccess, fileList, watchFolder)
end submitFolder
我认为您应该扩展Finder-tell结构,因为您以后仍在处理文件和文件夹:
tell application "Finder"
set myPath to the selection
--if multiple files selected
if (count of myPath) is greater than 1 then
set fileList to every item of myPath
repeat with i in fileList
if (isDirectory(i)) then
else
myBigLoop(initialSuccess, i, watchFolder)
end if
end repeat
else if (isDirectory(myPath)) then
submitFolder(myPath, watchFolder)
else
set isFolder to false
set initialSuccess to true
myBigLoop(initialSuccess, myPath, watchFolder)
end if
end tell
请包括你的处理程序。好的,我添加了它们@adayzdoneThanks@Mark,但我也有同样的行为。错误为“无法进入预期类型”。我尝试了
将I设置为I作为别名
,但不起作用。抱歉@gneek,如果没有人在我之前发布好的答案,我会调查。