マウント中のドライブのうち、起動ドライブを除いたものをアンマウントします。
NSWorkspace経由でアンマウントするものと、OLD Style AppleScriptでFinder経由でアンマウントするものを掲載しておきます。
ただし、Time Machineのバックアップドライブなど、NSWorkspace経由ではアンマウントできないものもあり、「どちらがいい」とも言い切れない様子です。
–> Download Blank Disk Image for test
AppleScript名:NSWorkSpace経由でアンマウント.scptd |
— – Created by: Takaaki Naganoya – Created on: 2018/10/07 — – Copyright © 2018 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions set aPath to retDrivePosixPath() of me if aPath = false then return set aWS to current application’s NSWorkspace’s sharedWorkspace() set aRes to aWS’s unmountAndEjectDeviceAtPath:aPath on retDrivePosixPath() tell application "Finder" set dList to properties of every disk whose startup is false and size > 0 if length of dList > 1 then –複数の対象ドライブがある場合にはユーザーに選択させる set dnList to name of every disk whose startup is false and size > 0 –set dnList to name of every disk whose startup is false set dRes to choose from list dnList set driveProp to (properties of disk dRes) set driveURL to URL of driveProp else if dList = {} then return false else set driveURL to URL of first item of dList end if end tell set dPath to ((current application’s |NSURL|’s URLWithString:driveURL)’s |path|()) as string return dPath end retDrivePosixPath |
AppleScript名:OLD style AppleScriptでアンマウント可能なドライブをアンマウント |
— – Created by: Takaaki Naganoya – Created on: 2018/10/07 — – Copyright © 2018 Piyomaru Software, All Rights Reserved — set dName to retEjectableDriveName() of me if dName = false then return tell application "Finder" to eject disk dName on retEjectableDriveName() tell application "Finder" set dList to properties of every disk whose startup is false and size > 0 if length of dList > 1 then –複数の対象ドライブがある場合にはユーザーに選択させる set dnList to name of every disk whose startup is false and size > 0 set dRes to choose from list dnList else if dList = {} then return false else set dRes to name of first item of dList end if return dRes end tell end retEjectableDriveName |
More from my site
(Visited 568 times, 2 visits today)