Mac 和 Windows PC 之間的最大區別之一是應用程序安裝。 在 Mac 上,安裝完成後,應安裝、卸載和刪除磁盤映像。這有點麻煩,特別是如果您必須在短時間內測試多個應用程序。
考慮到這一點,這裡有一些簡潔的小工作流程,您可以使用 Automator 在 Mac 上實現。每次在 Mac 上完成安裝應用程序時,您都可以使用其中任何一個彈出/卸載。 什麼時候 只需單擊幾下即可刪除磁盤映像。
讓我們從如何設置這些出色的 Automator 工作流程開始。
彈出時自動刪除 DMG 文件
步驟1: 打開 Automator 並選擇創建一個新文檔。從對話框中顯示的可用文檔類型中,[サービス]選擇。
第2步: 在右側面板的頂部,從下拉菜單中[入力なし]什麼時候[ファインダー]選擇每個選項,使最終結果如下圖所示。
第 3 步: 然後在 Automator 的左側面板中,搜索 Run AppleScript 操作並將其拖動到右側面板。 佔位符代碼出現在 AppleScript 窗口中。
刪除該代碼並將以下代碼複製並粘貼到腳本框中。
tell application "Finder"
set selection_list to selection
if (count selection_list)
display dialog ¬
"Please select a volume mounted from a disk image." with title ¬
"No Selection Found" with icon stop ¬
buttons ["OK"] default button 1
return
end if
set my_selection to item 1 of selection_list
set my_kind to kind of my_selection
set my_name to name of my_selection
if my_kind is not "Volume" then
display dialog ¬
"Please select a volume mounted from a disk image file." with title ¬
"Selection is not a Disk Image" with icon stop ¬
buttons ["OK"] default button 1
return
end if
set volume_list to paragraphs of (do shell script "hdiutil info | grep ^/dev/disk | grep -o '/Volumes/.*'")
set source_list to paragraphs of (do shell script "hdiutil info | grep ^image'-'alias | grep -o '/.*'")
set match_found to false
repeat with v from 1 to (count volume_list)
if "/Volumes/" & my_name = item v of volume_list then
set match_found to true
exit repeat
end if
end repeat
if match_found is not equal to true then
display dialog ¬
"The selected volume does not appear to be a Disk Image." with title ¬
"Could not find Disk Image" with icon stop ¬
buttons ["OK"] default button 1
return
else
set my_source to POSIX file (item v of source_list) as alias
move my_source to the trash
eject my_selection
--reveal my_source
end if
end tell
第4步: 保存此 Automator 服務並為其命名。
第 5 步: 完成此操作後,每次掛載磁盤映像時,只需選擇它,在 Finder 菜單中選擇服務,然後選擇彈出和刪除(或您剛剛創建的任何命名服務)即可卸載磁盤映像文件。並單擊刪除.
現在讓我們看看另一個實現完全相同目標的 Automator 工作流程。
將 DMG 文件拖到廢紙簍,它會自動彈出
正如標題所示,這個 Automator 工作流程允許您反向執行相同的操作,避免每次將已安裝的 DMG 文件拖到廢紙簍時出現此消息。
以下是創建它的步驟。
步驟1: 在 Automator 中創建一個新文檔,然後從可用文檔類型中選擇文件夾操作。
第2步: 在右側面板的頂部,從下拉菜單中[その他…]選擇。然後通過在彈出的對話框中鍵入 ~/.Trash 來使用該文件夾。
第 3 步: 然後在左側面板中,將 Run Shell Script 操作拖到右側面板。在出現的兩個下拉菜單中選擇 /usr/bin/python 作為參數。
第4步: 將腳本框中的佔位符腳本替換為以下腳本。
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
完成後,保存文件夾操作並退出 Automator。現在,每當您掛載 DMG 文件時,您只需將其拖到廢紙簍即可同時卸載它。
很酷的提示: 您還可以按照本教程末尾的說明為這些操作創建鍵盤快捷鍵。
請。 兩種不同的工作流程在 Mac 上啟用了非常有用的功能。現在您所要做的就是選擇您覺得更方便的那個。最好的?無論哪種情況,您都可以了解有關 Automator 的更多信息。樂趣!