[英]Is it possible to programmatically change the volume icon on a mounted drive on Mac OS X?
[英]OS X Applescript to Check if Drive Mounted and Mount It If Not
我正在嘗試編寫一個AppleScript,它將檢查是否已安裝網絡驅動器(在本例中為我的Time Capsule),如果沒有,則安裝它。 我已經想出了如何安裝Time Capsule,但是我對如何讓腳本檢查它是否先掛載以及只是退出(如果沒有,或者如果沒有掛載)感到茫然。
tell application "Finder"
mount volume "afp://AirPort%20Time%20Capsule._afpovertcp._tcp.local"
結束告訴
這是工作嗎?
set mountedDiskName to "AirPort Time Capsule"
set diskIsMounted to false
tell application "System Events" to set diskNames to name of every disk
if mountedDiskName is in diskNames then
set diskIsMounted to true
end if
if diskIsMounted then
log "Disk Found, unmounting now..."
do shell script "diskutil unmountDisk" & space & quoted form of mountedDiskName
else
log "Disk Not Found, mounting now…"
mount volume "afp://AirPort%20Time%20Capsule._afpovertcp._tcp.local"
end if
更新我認為您想在安裝時卸載磁盤,但這是錯誤的:)這里是一個較短的版本:
tell application "System Events" to set diskNames to name of every disk
if "AirPort Time Capsule" is in diskNames then
display dialog "Disk already mounted" buttons {"OK"} default button 1 with icon 1
else
mount volume "afp://AirPort%20Time%20Capsule._afpovertcp._tcp.local"
end if
...或者,如果您想要對話框中的磁盤名稱:
set diskName to "AirPort Time Capsule"
tell application "System Events" to set diskNames to name of every disk
if diskName is in diskNames then
display dialog quoted form of diskName & " is already mounted." & return buttons {"OK"} default button 1
else
mount volume "afp://AirPort%20Time%20Capsule._afpovertcp._tcp.local"
end if
您不必檢查所有磁盤的列表。 您可以詢問您想要的磁盤是否存在。
tell application "Finder"
if not (disk "Airport Time Capsule" exists) then
mount volume "afp://AirPort%20Time%20Capsule._afpovertcp._tcp.local"
end if
end tell
在使用Apple腳本的Finder上使用mount命令時,是否已經掛載共享似乎無關緊要。 無論如何,只需安裝它,Finder正確處理它(它不會再次安裝它,也不會大聲抱怨)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.