Skip to content

Instantly share code, notes, and snippets.

@ogawa
Last active December 12, 2015 02:08
Show Gist options
  • Save ogawa/4696314 to your computer and use it in GitHub Desktop.
Save ogawa/4696314 to your computer and use it in GitHub Desktop.
-- Eject and Sleep
-- ejectableなディスクをアンマウントしてスリープ
-- アンマウント状態で実行するとマウント
set diskNames to {"HD-PATU3", "Time Machine"}
tell application "Finder"
set disksToEject to {}
repeat with diskName in diskNames
if disk diskName exists then
set aDisk to (disk diskName)
if aDisk is ejectable then
set the end of disksToEject to aDisk
end if
else
try
do shell script "diskutil list | grep '" & diskName & "'"
do shell script "diskutil mount '" & diskName & "'"
on error number 1
-- skip
end try
end if
end repeat
if (count disksToEject) > 0 then
repeat with aDisk in disksToEject
try
eject aDisk
end try
end repeat
set userCanceled to false
try
set sleepAlertResult to display alert "コンピュータを今すぐスリープしてもよろしいですか?" message "何も操作をしないと、コンピュータは 10 秒で自動的にスリープします。" buttons {"キャンセル", "スリープ"} default button "スリープ" cancel button "キャンセル" as warning giving up after 10
on error number -128
set userCanceled to true
end try
if not userCanceled then
if (gave up of sleepAlertResult) or (button returned of sleepAlertResult is "スリープ") then
sleep
end if
end if
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment