0

首先,请允许我声明我完全讨厌 Mac。我对它们几乎没有经验,除了用 Objective-C 编程。

问题:我需要能够在闪存驱动器上的目录下启动便携式 Firefox 安装

[Drive root]/.assets/port/Firefox Portable.app

我可以得到一些帮助:

  1. 确保 shell 脚本将接受文件夹名称上的空格和句点
  2. 确保 shell 脚本将接受文件名中的空格
  3. 允许更改驱动器根目录,类似于 Windows 机器上的前导“/”。

提前致谢。

4

2 回答 2

2

在 OS Xopen(1)上,用于从命令行启动应用程序:

open "[/Volumes/[Drive file system name]/.assets/port/Firefox Portable.app"

与任何标准的 Unix shell 一样,将路径括在引号" "中可以防止空格和句点。

对于给定的闪存驱动器,卷文件系统名称将始终相同,除非您更改它。如果您事先不知道文件系统名称是什么,则需要搜索已安装的卷并猜测。

更准确地说,默认情况下,OS X 将尝试在挂载点使用相同的文件系统挂载 USB 驱动器,/Volumes/[Drive file system name]除非挂载点已被另一个类似名称的文件系统使用,在这种情况下,修改后的挂载点名称将被使用,通常是通过附加一些东西。或者您或某些程序可以在某个任意安装点手动安装它。因此,在最一般的情况下,您需要进行搜索。这取决于你想要做什么。

于 2011-06-08T21:42:10.950 回答
2

这应该可以解决问题。

cmd=$(ls -d /Volumes/*/.assets/port/Firefox\ Portable.app 2>/dev/null | head -1) && open "$cmd"

will try ls all Firefox on all mounted drives in the /Volumes and will launch the first one. (and do nothing, when not find any Firefox.)

Explanation:

  • ls -d try list in directory mode (so list the directory name and not it's content)
  • the backshlash in the Firefox\ Portable - mean escape the next char, (here the space)
  • 2>/dev/null - dont show errors (or you can try 2>&- too)
  • |head -1 - show only the 1st line from a result (if here is more lines)
  • and everything above assign into variable cmd - so if here is a command, the variable will contain a pathname
  • && open "$cmd" - open the application on the path stored in variable $cmd WHEN the previous command succeed (so here is a command)
于 2011-06-08T22:13:22.583 回答