Applescript将文件移动到自定义文件夹
我试图制作一个Applescript,将聚光灯下的文件移动到对话框指定的文件夹中。我想让脚本找到我输入的文件夹的路径,但是,我无法让它工作。有人能帮忙吗?提前感谢,如果您能告诉我为什么我的代码没有全部进入预览中的一个块,您将获得额外的积分:( 问题出在星号开始和结束的地方 这是代码Applescript将文件移动到自定义文件夹,applescript,Applescript,我试图制作一个Applescript,将聚光灯下的文件移动到对话框指定的文件夹中。我想让脚本找到我输入的文件夹的路径,但是,我无法让它工作。有人能帮忙吗?提前感谢,如果您能告诉我为什么我的代码没有全部进入预览中的一个块,您将获得额外的积分:( 问题出在星号开始和结束的地方 这是代码 repeat 1 times set spotlightquery to quoted form of text returned of (display dialog "What do you want
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
你有这两行…我相信你希望这两个变量匹配
set getMovedTo to "Macintosh HD:Users:aaronmcclellan:Desktop:Coding:C"
move file founditems to folder moveTo
foundItems
是字符串列表,但您试图将其视为文件。移动行的计算方式如下:
move (file founditems) to (folder moveTo)
这会导致错误,因为无法将列表foundItems
转换为文件
您需要将每个路径分别转换为一个文件:
repeat with theFile in foundItems
move file theFile to folder moveTo
end repeat
你真的应该首先调试并找出哪一行失败了。将显示对话框放在检查点并验证变量是否正确。然后你可以询问为什么某一行或块不能正常工作,而不是整个例程。我在代码开始失败的地方加了星号。谢谢!你到底在哪一行上出错了,你到底遇到了什么样的错误?是的,否则很难帮助你。在if块周围加一个Try块,然后报告报告报告的错误。其他问题:C文件夹和桌面选项是否正常工作?为什么你使用DispDialog而不使用Choose Folder对话框?你是用旧的:mac:format还是posix/path/format键入文件夹路径?I对于posix,您需要更改移动行以适应。对不起,各位。我有工作要做,因此无法帮助阅读您的评论。我添加了错误发生的位置。您是正确的。但是,这是一个简单的修复方法。感谢您指出。