OS X Applescript检查驱动器是否已安装,是否已安装 [英] OS X Applescript to Check if Drive Mounted and Mount It If Not

查看:115
本文介绍了OS X Applescript检查驱动器是否已安装,是否已安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆