我正在尝试创建一个Applescript,将一个聚光灯文件移动到一个对话框指定的文件夹中。我希望脚本找到我输入的文件夹的路径,但是,我无法让它工作。有人可以帮忙吗?如果你能告诉我为什么我的代码并没有在我的预览中进入一个区块,请提前和奖励积分:( !!
问题出现在星号的开始和结束处。
这是代码。
repeat 1 times
set spotlightquery to quoted form of text returned of (display dialog "What do you want to search?" default answer "" buttons {"Search!"} default button 1)
if spotlightquery = "''" then
exit repeat
end if
set thefolders to {path to home folder}
set founditems to {}
repeat with i in thefolders
set thepath to quoted form of POSIX path of i
if exists thepath then
set command to "mdfind -onlyin " & thepath & " " & spotlightquery
set founditems to founditems & (paragraphs of (do shell script command))
end if
end repeat
if founditems = {} then
display dialog "No items found." buttons {"OK"} default button 1
exit repeat
end if
display dialog "" & founditems & "" buttons {"OK"} default button 1
set location to the button returned of (display dialog "Where would you like to move it?" buttons {"C Folder", "Desktop", "Other"} default button 3)
if location = "C Folder" then
tell application "Finder"
set moveTo to "Macintosh HD:Users:aaronmcclellan:Desktop:Coding:C"
move file founditems to folder moveTo
end tell
else
if location = "Desktop" then
tell application "Finder"
set moveTo to the path to desktop folder
move file founditems to folder moveTo
end tell
end if
*if location = "Other" then
set fold to the text returned of (display dialog "Where would you like to move it?" default answer "" buttons {"OK"} default button 1)
set moveTo to fold
tell application "System Events"
##error occurs here
move file founditems to folder moveTo
end tell
end if*
end if
end repeat
答案 0 :(得分:1)
你有这两行...我相信你想要这两个变量匹配吗?
set getMovedTo to "Macintosh HD:Users:aaronmcclellan:Desktop:Coding:C"
move file founditems to folder moveTo
答案 1 :(得分:1)
foundItems
是字符串列表,但您尝试将其视为文件。移动线的评估方式如下:
move (file founditems) to (folder moveTo)
导致错误的原因是列表foundItems
无法转换为文件。
您需要将每个路径分别转换为文件:
repeat with theFile in foundItems
move file theFile to folder moveTo
end repeat