MacOSX:通过 AppleScript 获取 Finder 的当前目录时避免挂起
目前我正在使用这个AppleScript来获取Finder的当前目录:
tell application "Finder"
return POSIX path of ((folder of the front window) as text)
end tell
当你经常运行它时,例如将其放入文件中并运行 while true;睡觉1; osascript -ss myscript;完成
后,您会发现 Finder 每次都会挂起一点。
如何避免挂起?还有其他方法可以获取该信息吗?
Currently I am using this AppleScript to get the current directory of Finder:
tell application "Finder"
return POSIX path of ((folder of the front window) as text)
end tell
When you run this quite often, e.g. put it into a file and run while true; do sleep 1; osascript -ss myscript; done
, you will see that each time, Finder hangs a bit.
How can I avoid the hanging? Is there any other way to get that information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你真的不能。 Applescript 并不以其速度而闻名,本质上,您是在要求 Finder 重新计算它理所当然可能无法跟踪的内容。
如果您反复要求 Finder 查找此信息,那么您可能需要重新考虑您的方法。例如,您不需要打开 Finder 窗口即可对目标文件集执行操作。
You can't really. Applescript isn't known for its speed, and you are, essentially, asking the Finder to recalculate something it may not keep track of as a matter of course.
If you are asking the Finder repeatedly to find this piece of information, then you might want to reconsider your approach. For example, you don't need to have a Finder window open to perform actions on a targeted set of files.