ISOイメージを作るHDIUTIL版
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue()
set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue()
####################################
####デバイス名取得
####################################
##コマンド整形
set strCommandText to ("/bin/df -k") as text
##コマンド実行
set strDfResponse to (do shell script strCommandText) as text
##Stringsに
set ocdiDfResponse to refMe's NSString's stringWithString:(strDfResponse)
##改行指定
set ocidCharacterSet to refMe's NSCharacterSet's newlineCharacterSet()
##改行でリスト
set ocidStringArray to ocdiDfResponse's componentsSeparatedByCharactersInSet:(ocidCharacterSet)
##リストの数だけ繰返し
repeat with itemStringArray in ocidStringArray
set strItemStringArray to itemStringArray as text
##スペース指定
set ocidCharacterSet to refMe's NSCharacterSet's whitespaceCharacterSet()
set ocidDevArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
##デバイス名を取得
set ocidDevicePath to (ocidDevArray's objectAtIndex:0)
###CD/DVDデバイス用の整形表現
set strRegPattern to "/dev/disk[0-9]+"
###正規表現で判定項目を作って(マッチなら)
set codiPridic to refMe's NSPredicate's predicateWithFormat_("(SELF MATCHES %@)", strRegPattern)
###CD判定
set boolCD to (codiPridic's evaluateWithObject:(ocidDevicePath))
if boolCD is ocidTrue then
set strDevicePath to ocidDevicePath as text
set ocidCharacterSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:"/")
set ocidVolArray to (itemStringArray's componentsSeparatedByCharactersInSet:(ocidCharacterSet))
set strDiskName to (ocidVolArray's lastObject()) as text
end if
end repeat
####################################
####ディスクの表示名
####################################
set strMountPath to ("/Volumes/" & strDiskName) as text
tell application "Finder"
set aliasMountPath to (POSIX file strMountPath) as alias
end tell
####################################
####ダイアログ
####################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "iso"
set strDefaultName to (strDiskName & "." & strFileExtension) as text
set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
set strSaveFilePath to (POSIX path of aliasFilePath) as text
####ドキュメントのパスをNSString
set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
####ドキュメントのパスをNSURLに
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
###拡張子取得
set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
###ダイアログで拡張子を取っちゃった時対策
if strFileExtensionName is not strFileExtension then
set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:strFileExtension
end if
set strSaveFilePath to (ocidSaveFilePathURL's |path|()) as text
####################################
#### まずアンマウント
####################################
try
set strCommandText to ("/usr/sbin/diskutil unmount " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText
on error
set strCommandText to ("/usr/bin/sudo /sbin/umount " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText with administrator privileges
end try
###5秒待つ
delay 5
####################################
#### ISOイメージ作成makehybrid
####################################
###AudioCDはこれ
set strCommandText to ("/usr/bin/hdiutil makehybrid -iso -joliet -o \"" & strSaveFilePath & "\" " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText
delay 5
return
####################################
#### イジェクト する場合
####################################
try
set strCommandText to ("/usr/bin/drutil eject") as text
do shell script strCommandText
on error
try
set strCommandText to ("/usr/sbin/diskutil eject " & strDevicePath & "") as text
do shell script strCommandText
on error
set strCommandText to ("/usr/sbin/hdiutil eject \"" & strMountPath & "\" -force") as text
do shell script strCommandText
end try
end try
####################################
#### 再度マウントする場合
####################################
set strCommandText to ("/usr/sbin/diskutil mount " & strDevicePath & "") as text
log strCommandText
do shell script strCommandText
return
| 固定リンク
「CD/DVD」カテゴリの記事
- com.apple.CD-DVD-Settings.extensionシステム設定を開く(2023.07.19)
- [com.apple.digihub]com.apple.digihub設定スクリプト(2023.07.19)
- [CD/DVD]基本(2023.05.20)
- ISOイメージを作るDD版.scpt(2023.05.20)
- ISOイメージを作るHDIUTIL版(2023.05.20)