【发布时间】:2014-02-05 03:35:53
【问题描述】:
我正在尝试制作一个 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
【问题讨论】:
-
你真的应该先调试并找出哪条线出错了。将显示对话框放在检查点并验证变量是否正确。然后你可以问为什么一个特定的行或块不工作,而不是整个例程。
-
我在代码开始失败的地方添加了星号。谢谢!
-
您到底在哪一行得到错误,究竟是什么错误?
-
是的,否则很难提供帮助。在 if 块周围包裹一个 Try 块并报告报告的错误。其他问题:C 文件夹和桌面选项是否有效?为什么您使用 DispDialog 而不是 Other 的选择文件夹对话框?您是在 old:mac:format 还是 posix/path/format 中键入文件夹路径?如果是 posix,则需要更改移动线以适应。
-
对不起大家。我有工作要做,所以我无法帮助并阅读您的 cmets。我添加了错误发生的位置。
标签: applescript