【问题标题】:is it possible to open a folder in Finder in the *current* space from the command line?是否可以从命令行在 *current* 空间中的 Finder 中打开一个文件夹?
【发布时间】:2014-06-03 10:47:58
【问题描述】:

我想发出一个终端命令(调用 AppleScript 很好)以在 当前 空间的 Finder 窗口中打开一个路径。

如果路径在另一个空间的 Finder 中打开,我不想切换到该空间或将该 finder 窗口移动到当前空间。如果路径已经在当前空间的 Finder 窗口中打开,则可以关注它或打开一个新的 Finder 窗口。

我运行了很多为不同任务设置的空间,我不想从我可能正在使用的任何其他空间中删除 Finder 窗口或切换到任何其他空间。

【问题讨论】:

  • 只使用 open 命令怎么样?例如“打开/应用程序”
  • @Merlin069 如果在另一个空间中打开该文件夹,则不会在 当前 空间中打开 Finder 窗口。问题是关于在 current 空间中打开文件夹的 Finder 窗口。
  • 抱歉,我没有注意到您指定在同一位置打开了一个文件夹。

标签: macos finder


【解决方案1】:

在 Applescript 中,例如打开 Applications 文件夹:-

tell application "Finder"
    make new Finder window to folder "Applications" of startup disk
end tell

您可以将其保存为脚本并使用 osascript 命令从命令行调用它,也可以使用 osascript 的 -e 参数直接执行它:-

osascript -e 'tell application "Finder" to make new Finder window to folder "Applications" of startup disk'

如果你想打开一个特定的路径,而不是一个命名的文件夹,你可以引用这个路径:-

POSIX file "/some/directory/path"

所以,一个完整的脚本应该是:-

tell application "Finder"
    activate
    make new Finder window to (POSIX file "/some/directory/path")
end tell

注意:activate 命令聚焦 Finder 窗口,这是可选的。

【讨论】:

  • 感谢您的回复。我想我在 Finder 术语方面说错了,我想做的是打开一个 path。问题stackoverflow.com/questions/11261516/… 帮助我拼凑了一个工作脚本。你介意我编辑它以供其他人参考吗?
  • 当然,如果它使答案更好,那就去吧。
猜你喜欢
  • 2012-10-03
  • 2012-06-30
  • 2016-08-12
  • 2010-11-06
  • 1970-01-01
  • 2022-06-12
  • 1970-01-01
  • 2014-12-11
  • 2011-10-01
相关资源
最近更新 更多