从挂载点获取.dmg的路径

发布于 2024-08-16 01:05:04 字数 220 浏览 1 评论 0原文

我正在寻找一种方法来获取已安装磁盘映像的 .dmg 路径及其安装点。

我想编写一个“简单”的 Finder 服务,用于弹出磁盘映像并销毁随附的 .dmg。弹出是微不足道的,但我不知道如何找出 .dmg 的路径,只给出安装点。

diskutil 似乎不知道或没有说。

它适用于脚本,因此首选 AppleScript 或基于 shell 的建议。

I'm looking for a way to get the .dmg path of a mounted disk image with just its mount point.

I want to write a "simple" Finder service that ejects the disk image and trashes the accompanying .dmg. The ejecting is trivial, but I'm at a loss as to how to figure out the path of the .dmg, given just the mount point.

diskutil doesn't seem to know or isn't saying.

It's for a script, so AppleScript- or shell-based suggestions are preferred.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞梦里开花 2024-08-23 01:05:04

使用 hdiutil info 获取有关当前安装的映像的信息。然后
使用 hdiutil detach /Mount/Point 卸载所有文件系统,并分离映像。

如果安装了多个图像,您需要解析 hdiutil info 的输出以找到正确的图像路径。使用 plist 输出格式 hdiutil info -plist 并将其运行到例如带有 plistlib 或使用系统事件中的属性列表套件的AppleScript。

这是一个快速但肮脏的 python 脚本,可以给你一个想法。使用 python 解释器很容易探索选项:

>>> import plistlib
>>> from subprocess import Popen, PIPE
>>> output = Popen(["hdiutil", "info", "-plist"], stdout=PIPE).communicate()[0]
>>> pl = plistlib.readPlistFromString(output)
>>> for image in pl['images']:
...   for se in image['system-entities']:
...       if se.get('mount-point') == '/Volumes/blah':
...          print image['image-path']
/Path/To/blah.dmg

Use hdiutil info to get the information about currently mounted images. Then
use hdiutil detach /Mount/Point to dismount all file systems, and detach the image.

You'll need to parse the output from hdiutil info to find the right image-path if multiple images are mounted. It will probably be more robust to use the plist output format hdiutil info -plist and run that into, say, a python script with plistlib or an AppleScript using the Property List Suite from System Events.

Here's a quick and dirty python script to give you an idea. It's easy to explore options using the python interpreter:

>>> import plistlib
>>> from subprocess import Popen, PIPE
>>> output = Popen(["hdiutil", "info", "-plist"], stdout=PIPE).communicate()[0]
>>> pl = plistlib.readPlistFromString(output)
>>> for image in pl['images']:
...   for se in image['system-entities']:
...       if se.get('mount-point') == '/Volumes/blah':
...          print image['image-path']
/Path/To/blah.dmg
给我一枪 2024-08-23 01:05:04

启动终端,执行:

$ cd /Volumes
$ hdiutil info

可疑 dmg 文件的位置将显示在图像路径

cd 下到该位置,然后执行:

$ ls filename

在 Finder 中卸载卷,最后在终端中执行:

$ rm filename

祝你好运。

Start Terminal, do:

$ cd /Volumes
$ hdiutil info

The location of suspected dmg-files will show up under image-path

cd to that location, and do:

$ ls filename

Unmount volume in Finder, and finally in Terminal:

$ rm filename

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文