property theBkImage : "background-820x460.png"
on run
set theWithPrompt to "フォルダからDMG形式のディスクイメージを作成します"
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set theFileType to "public.folder,public.directory" as text
set AppleScript's text item delimiters to {","}
set theFileTypeList to every text item of theFileType
set AppleScript's text item delimiters to {""}
set DropObj to (choose folder default location aliasDefaultLocation ¬
with prompt theWithPrompt ¬
invisibles true ¬
with multiple selections allowed and showing package contents)
set DropObj to DropObj as list
open (DropObj)
end run
on open DropObj
set listFormatList to ¬
{"UDRW:read/write", ¬
"UDRO:read-only", ¬
"UDCO:ADC-comp", ¬
"UDZO:zlib-comp", ¬
"ULFO:lzfse-comp", ¬
"ULMO:lzma-comp", ¬
"UDBZ:bzip2-comp", ¬
"UDTO:master", ¬
"UDSP:SPARSE", ¬
"UDSB:SPARSEBUNDLE", ¬
"UFBI:MD5checksum"} as list
set theFormat to (choose from list listFormatList with title "フォーマット選択" with prompt "フォーマット選択" default items "UDRO:read-only" empty selection allowed no with multiple selections allowed) as text
set AppleScript's text item delimiters to ":"
set listFormat to every text item of theFormat
set AppleScript's text item delimiters to ""
set theFormat to (item 1 of listFormat) as text
set listFormatList to ¬
{"HFS+:通常拡張", ¬
"HFS+J:ジャーナリング", ¬
"HFSX:大小文字判別", ¬
"JHFS+X:ジャーナリング大小文字判別", ¬
"APFS:現行macOS10.13以上", ¬
"FAT32:Windows互換汎用", ¬
"ExFAT:Windows互換推奨", ¬
"UDF:ディスクマスター用", ¬
"UFBI:MD5checksum"} as list
set theFileSystem to (choose from list listFormatList with title "ファイルシステム選択" with prompt "ファイルシステム選択" default items "HFS+J:ジャーナリング" empty selection allowed no with multiple selections allowed) as text
set AppleScript's text item delimiters to ":"
set listFileSystem to every text item of theFileSystem
set AppleScript's text item delimiters to ""
set theFileSystem to (item 1 of listFileSystem) as text
repeat with objFiles in DropObj
set theAlias to objFiles as alias
tell application "Finder"
set aliasFolderContainerDir to (container of theAlias) as alias
set theFolderContainerPath to (POSIX path of aliasFolderContainerDir) as text
end tell
set theFileInfo to info for objFiles as alias
set theFolderName to (name of theFileInfo) as text
set theOrgPath to (POSIX path of objFiles) as text
tell application "Finder"
set aliasMyPathDir to (container of (path to me) as alias) as alias
set theMyPathDir to (POSIX path of aliasMyPathDir) as text
end tell
set theBgimagesPath to ("" & theMyPathDir & theBkImage) as text
set theBgimagesDistPath to ("" & theOrgPath & ".background.png") as text
set theCmdCom to ("ditto \"" & theBgimagesPath & "\" \"" & theBgimagesDistPath & "\"") as text
do shell script theCmdCom
log theCmdCom
set theCmdCom to ("hdiutil create -volname \"" & theFolderName & "\" -srcfolder \"" & theOrgPath & "\" -ov -fs " & theFileSystem & " -format UDIF \"" & theFolderContainerPath & theFolderName & ".tmp.dmg\"") as text
do shell script theCmdCom
delay 1
set theCmdCom to ("hdiutil attach -noverify -noautofsck -noidme -quiet \"" & theFolderContainerPath & theFolderName & ".tmp.dmg\"") as text
do shell script theCmdCom
set theDiskwindowPath to ("/Volumes/" & theFolderName) as text
tell application "Finder"
set aliasDiskwindowPath to POSIX file theDiskwindowPath as alias
set objFinder to (make new Finder window)
activate
delay 1
tell objFinder
activate
set theMakeWindowID to id
end tell
delay 1
tell window id theMakeWindowID
activate
set target to aliasDiskwindowPath
set toolbar visible to false
set pathbar visible to false
set current view to icon view
set sidebar width to 0
set position to {50, 50}
set bounds to {50, 50, 820, 460}
set statusbar visible to false
set arrangement of its icon view options to arranged by name
try
set background picture of its icon view options to file ".background.png"
on error
delay 2
set background picture of its icon view options to file ".background.png"
end try
end tell
delay 1
close window id theMakeWindowID
end tell
try
tell application "Finder"
activate
delay 1
eject disk theFolderName
end tell
on error
try
set theCmdCom to ("diskutil unmount \"/Volumes/" & theFolderName & "\"") as text
do shell script theCmdCom
end try
try
set theCmdCom to ("umount -f \"/Volumes/" & theFolderName & "\"") as text
do shell script theCmdCom
end try
end try
set theCmdCom to ("hdiutil convert -format UDRO \"" & theFolderContainerPath & theFolderName & ".tmp.dmg\" -o \"" & theFolderContainerPath & theFolderName & ".dmg\"") as text
do shell script theCmdCom
try
set theCmdCom to ("hdiutil detach \"/Volumes/" & theFolderName & "\" -force") as text
do shell script theCmdCom
end try
set thetmpDMGpath to ("" & theFolderContainerPath & theFolderName & ".tmp.dmg") as text
tell application "Finder"
set aliastmpDMGpath to POSIX file thetmpDMGpath as alias
move file aliastmpDMGpath to trash
end tell
set theCmdCom to ("rm -f \"" & theBgimagesDistPath & "\"") as text
do shell script theCmdCom
end repeat
end open