gpt4 book ai didi

macos - OS X Applescript 检查驱动器是否已安装,如果未安装则安装

转载 作者:行者123 更新时间:2023-12-01 09:55:20 25 4
gpt4 key购买 nike

我正在尝试编写一个 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

关于macos - OS X Applescript 检查驱动器是否已安装,如果未安装则安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29332873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com