Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@moyashi
Last active December 24, 2019 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moyashi/dff522a355ea19dfb8bcd6b46b5085cf to your computer and use it in GitHub Desktop.
Save moyashi/dff522a355ea19dfb8bcd6b46b5085cf to your computer and use it in GitHub Desktop.
SDカード等のMS-DOSフォーマットのディスクをイジェクトするAppleScript
display notification "イジェクト処理開始"
set dl to {}
repeat with l in every paragraph of (do shell script "mount | grep -e 'msdos\\|exfat' | awk '{print $1}'")
set end of dl to (do shell script "diskutil info " & l & " | grep 'Volume Name:' | sed -e 's/Volume Name: //' | sed -e 's/^ *//'")
end repeat
if ((count of dl) is greater than 0) then
tell application "Finder"
repeat with i in dl
if (exists disk i) then
eject disk i
repeat 20 times
delay 0.5
if (not (exists disk i)) then
display notification i & "がイジェクトされました"
exit repeat
end if
end repeat
end if
end repeat
end tell
else
display notification "イジェクト対象のディスクがありませんでした"
end if
@moyashi
Copy link
Author

moyashi commented Dec 19, 2019

BetterTouchToolでCommand + Ctrl + Eに割り当てて実行しています。
「Apple Scriptを実行する(ブロック)」で実行しないと通知が表示されません。
「Apple Scriptを実行する(バックグラウンドで非同期)」でも実行できますが、通知が表示されません。

@moyashi
Copy link
Author

moyashi commented Dec 24, 2019

exFATが対象にならなかったんで修正

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment