DMGファイルはMacにとって、とても便利なディスクイメージです。
圧縮が可能で暗号化にパスワードの指定
リソースフォークを保持出来る(HFS+等を選択すれば)
サーバー等から呼び出した時にPKGを実行出来る等々
Macな環境内では『ある意味で』最強かも(まぁちょっと破損が怖いけど)
ファイルを選択
↓
ファイル名のフォルダを作成してその中にファイルを入れる
↓
ファイル名のDMGを作る
と
いった流れ
(*
makeDMG4File.scpt
20160829 初回作成
選んだファイルをフォルダに入れてDMGファイルに変換します。
*)
---■■■■ダブルクリックの始まり
onrun
---プロンプトの文言改行が使えます\nを入れます
settheWithPromptto"ディスクイメージに変換します"
---ファイル選択ダイアログのデフォルトのディレクトリ
settheDownloadsFolderPathtopath todesktop folderfromuser domain
---Uniform Type Identifier指定
---詳しくは http://goo.gl/6jAQa Uniform Type Identifier
settheFileTypeto"" astext
---↑のファイルタイプをリスト形式に整形する
setAppleScript's text item delimitersto {","}
settheFileTypeListtoeverytext itemoftheFileType
---ダイアログを出して選択されたファイルは「open」に渡す
open (choose filedefault locationtheDownloadsFolderPath¬
with prompttheWithPrompt¬
of typetheFileTypeList¬
invisiblestrue¬
withmultiple selections allowedwithoutshowing package contents)
(* フォルダをの場合はこちらを
open (choose folder default location theDownloadsFolderPath ¬
with prompt theWithPrompt ¬
invisibles true ¬
with multiple selections allowed without showing package contents)
*)
endrun
---openドロップの始まり
onopenDropObj
--- 繰り返しの始まり
repeatwithObjFilesinDropObj
---オブジェクトのエイリアスを取得
settheAliastoObjFilesasalias
---オブジェクトの情報を取得
settheFileInfotoinfo forObjFilesasalias
---エイリアス形式をテキストに変換
settheAliasPathtotheAliasastext
---ファイル名を取得
settheNameto (nameoftheFileInfo) astext
---拡張子を取得
settheNameExtensionto (name extensionoftheFileInfo) astext
----
if (folderoftheFileInfo) isfalsethen
---エイリアスパスからファイル名を引いてディレクトリを取得
settheDirNametomydoReplace(theAliasPath, theName, "") astext
elseif (folderoftheFileInfo) istruethen
---エイリアスパスからファイル名を引いてディレクトリを取得
settheDirNametomydoReplace(theAliasPath, (":" & theName), "") astext
endif
---ファイル名から拡張子を取り除く
settheShortNametomydoReplace(theName, ("." & theNameExtension), "") astext
---ディレクトリをUNIXパス形式に
settheDirPathtoPOSIX pathoftheDirNameastext
---日付けと時間からテンポラリー用のフォルダ名を作成
settheNowTimeto (mydoDateAndTIme(current date)) astext
-----------------------------------フォルダを作って
tellapplication"Finder"
try
makenewfolderatfoldertheDirNamewith properties {name:theNowTime}
onerror
log"フォルダの作成時にエラーが発生しました"
endtry
endtell
-----------------------------------ファイルを中に入れて
tellapplication"Finder"
try
moveObjFilestofoldertheNowTimeoffoldertheDirNamewithreplacing
onerror
log"ファイルの移動時にエラーが発生しました"
endtry
endtell
-----------------------------------フォルダの名前をファイル名に変更する
tellapplication"Finder"
try
setnameoffoldertheNowTimeoffoldertheDirNametotheShortName
onerror
log"フォルダの名称変更時にエラーが発生しました"
endtry
endtell
-----------------------------------DMGを作成する
---パス指定
settheSrcFolderto (POSIX pathof (theDirPath& theShortName)) astext
---コマンド実行
do shell script"hdiutil create -fs HFS+ -srcfolder '" & theSrcFolder& "' -volname '" & theShortName& "' '" & theDirPath& theShortName& ".dmg'"
---繰り返しの終了
endrepeat
endopen
----ここからサブルーチン
todoReplace(theText, orgStr, newStr)
setoldDelimtoAppleScript's text item delimiters
setAppleScript's text item delimiterstoorgStr
settmpListtoeverytext itemoftheText
setAppleScript's text item delimiterstonewStr
settmpStrtotmpListastext
setAppleScript's text item delimiterstooldDelim
returntmpStr
enddoReplace
------------------------------
todoDateAndTIme(theDate)
setyto (yearoftheDate)
setmtomymonthNumStr(monthoftheDate)
setdtodayoftheDate
sethmstotimeoftheDate
sethhtohofsec2hms(hms)
setmmtomofsec2hms(hms)
setsstosofsec2hms(hms)
return (yastext) & myzero1(m) & myzero1(d) & "_" & zero1(hh) & zero1(mm) & zero1(ss)
return (yastext) & myzero1(m) & myzero1(d)
enddoDateAndTIme
------------------------------
tomonthNumStr(theMonth)
setmonListto {January, February, March, April, May, June, July, August, September, October, November, December}
repeatwithifrom 1 to 12
ifitemiofmonLististheMonththenexitrepeat
endrepeat
returni
endmonthNumStr
------------------------------
tosec2hms(sec)
setretto {h:0, m:0, s:0}
sethofrettosecdivhours
setmofretto (sec - (hofret) * hours) divminutes
setsofrettosecmodminutes
returnret
endsec2hms
------------------------------
tozero1(n)
ifn< 10 then
return"0" & n
else
returnnastext
endif
endzero1
「makeDMG4File.scpt.zip」をダウンロード