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

编程入门 行业动态 更新时间:2024-10-18 16:47:50
本文介绍了OS X Applescript 检查驱动器是否已安装,如果未安装则安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试编写一个 AppleScript,它会检查网络驱动器(在本例中为我的 Time Capsule)是否已安装,如果没有,则安装它.我已经知道如何挂载 Time Capsule,但我不知道如何让脚本先检查它是否已挂载,如果挂载则退出,否则挂载.

I am trying to write an AppleScript that will check if a network drive (in this case, my Time Capsule) is mounted and, if not, mount it. I've figured out how to mount the Time Capsule, but I am at a loss over how to have the script check whether it is mounted first and just exit if it is, or mount it if not.

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


更新我以为你想在挂载时卸载磁盘,但这是错误的:) 这里有一个较短的版本:


Update I thought you want to unmount the disk when mounted but that was wrong :) here a shorter version:

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

...或者,如果您想在对话框中显示磁盘名称:

…or, if you want the disk name in the dialog:

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

这篇关于OS X Applescript 检查驱动器是否已安装,如果未安装则安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 14:55:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915853.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:驱动器   OS   Applescript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!