【问题标题】:Unmount OSX volumes when placed in trash放入垃圾箱时卸载 OSX 卷
【发布时间】:2016-06-29 08:13:11
【问题描述】:

我找到了这篇文章...http://www.guidingtech.com/26874/eject-delete-dmg-files-automatically/我的问题与页面的第二部分有关。

它在 El Cap 中似乎不再起作用了。尝试了终端中的各个行,发现需要将“弹出”更改为“分离”。我还将 ### 更改为 === 以匹配 detach 命令的输出,但它似乎不起作用。我知道文件夹操作正在触发,因为我在 automator 中选中了“在工作流运行时显示此操作”,它确实会弹出。

这是我所拥有的:

import string, os, sys

lines = os.popen("hdiutil info").readlines()
should_eject = False

for line in lines:
    if line.startswith("image-alias"):
        path = line.split(":")[1]
        image_path = path.lstrip().rstrip()
        if image_path in sys.argv:
            should_eject = True
        elif line.startswith("/dev/") and should_eject is True:
            os.popen("hdiutil detach -force " % line.split()[0])
            should_eject = False
        elif line.startswith("==="):
            should_eject = False

【问题讨论】:

  • 在下面回答了我自己的问题

标签: python macos unmount


【解决方案1】:
import string, os, sys

lines = os.popen("hdiutil info").readlines()
should_eject = False

for line in lines:
    if line.startswith("image-alias"):
        path = line.split(":")[1]
        image_path = path.lstrip().rstrip()
        if image_path in sys.argv:
            should_eject = True
    elif line.startswith("/dev/") and should_eject is True:
        os.popen("hdiutil eject %s" % line.split()[0])
        should_eject = False
    elif line.startswith("==="):
        should_eject = False

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多