AppleScript Disk

[UDSP]SPARSE - スパースディスクイメージを作成する


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "UniformTypeIdentifiers"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015
016#############################
017###ダイアログを前面に出す
018set strName to (name of current application) as text
019if strName is "osascript" then
020  tell application "Finder" to activate
021else
022  tell current application to activate
023end if
024set appFileManager to refMe's NSFileManager's defaultManager()
025set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
026set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
027set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
028#
029set strMes to "フォルダを選んでください" as text
030set strPrompt to "フォルダを選択してください" as text
031try
032  set aliasDirPath to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation with invisibles and showing package contents without multiple selections allowed) as alias
033on error
034  log "エラーしました"
035  return "エラーしました"
036end try
037#フォルダパス
038set strDirPath to (POSIX path of aliasDirPath) as text
039set ocidDirPathStr to refMe's NSString's stringWithString:(strDirPath)
040set ocidDirPath to ocidDirPathStr's stringByStandardizingPath()
041set ocidDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPath) isDirectory:(true)
042#
043set strDirName to (ocidDirPathURL's lastPathComponent()) as text
044set ocidContainerDirPathURL to ocidDirPathURL's URLByDeletingLastPathComponent()
045#sparse
046set ocidDmgFilePathURL to ocidDirPathURL's URLByAppendingPathExtension:("sparseimage")
047#通常DMG
048#set ocidDmgFilePathURL to ocidDirPathURL's URLByAppendingPathExtension:("dmg")
049#ディスクイメージの保存先パス
050set strSaveFilePath to ocidDmgFilePathURL's |path| as text
051
052(*
053■フォーマット  -format
054UDRO - 読み出し専用
055UDCO - 圧縮(ADC)
056UDZO - 圧縮
057UDBZ - compressed (bzip2), deprecated
058ULFO - 圧縮(lzfse)
059ULMO - 圧縮(lzma)
060UFBI - 装置全体
061IPOD - iPodイメージ
062UDSB - sparsebundle
063UDSP - スパース
064UDRW - 読み出し/書き込み
065UDTO - DVD/CDマスター
066UNIV - ハイブリッドイメージ(HFS+/ISO/UDF)
067SPARSEBUNDLE - スパースバンドルディスクイメージ
068SPARSE - スパースディスクイメージ
069UDIF - 読み出し/書き込みディスクイメージ
070UDTO - DVD/CDマスター
071■新規イメージ  -type
072SPARSEBUNDLE - スパースバンドルディスクイメージ
073SPARSE - スパースディスクイメージ
074UDIF - 読み出し/書き込みディスクイメージ
075UDTO - DVD/CDマスター
076■パーテーション -layout
077MBRSPUD - 単一パーティション - マスターブートレコード
078SPUD - 単一パーティション - Appleパーティションマップ
079UNIVERSAL CD - CD/DVD
080NONE - パーティションマップなし
081GPTSPUD - 単一パーティション - GUIDパーティションマップ
082SPCD - 単一パーティション - CD/DVD
083UNIVERSAL HD - ハードディスク
084ISOCD - 単一パーティション - CD/DVD(ISOデータ)
085■ファイルシステム -fs
086UDF - Universal Disk Format (UDF)
087ExFAT: Windows推奨
088FAT:MSDOS互換汎用
089FAT12:Windows互換汎用
090FAT16:Windows互換汎用
091FAT32:Windows互換汎用
092HFS+:通常拡張
093HFSX:大小文字判別
094HFS+J:ジャーナリング
095JHFS+X:ジャーナリング大小文字判別
096
097APFS:現行macOS10.13以上
098Case-sensitive APFS:現行macOS10.13以上
099*)
100#コマンド実行
101#Sparse Disk パーテーション無し スパース HFS拡張 大文字小文字判定ジャーナル有
102set strCommandText to ("/usr/bin/hdiutil  create -volname \"" & strDirName & "\" -srcfolder  \"" & strDirPath & "\" -layout NONE -format UDSP  -fs JHFS+X -o \"" & strSaveFilePath & "\"") as text
103
104#APFS 大文字小文字判定
105# set strCommandText to ("/usr/bin/hdiutil  create -volname \"" & strDirName & "\" -srcfolder  \"" & strDirPath & "\" -layout GPTSPUD -format UDRW  -fs Case-sensitive\\ APFS -o \"" & strSaveFilePath & "\"") as text
106
107log strCommandText
108set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text
109try
110  do shell script strExecCommand
111on error
112  #エラーになったらfalseを戻す
113  return false
114end try
115
AppleScriptで生成しました

|

DMGを読取専用 書き込み可能にコンバートする

読取専用に
AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "UniformTypeIdentifiers"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015
016#############################
017###ダイアログを前面に出す
018set strName to (name of current application) as text
019if strName is "osascript" then
020  tell application "Finder" to activate
021else
022  tell current application to activate
023end if
024############ デフォルトロケーション
025set appFileManager to refMe's NSFileManager's defaultManager()
026set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
027set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
028set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
029tell application "Finder"
030  set aliasDefaultLocation to container of (path to me) as alias
031  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
032end tell
033
034############UTIリスト
035set listUTI to {"com.apple.disk-image-udif"}
036set strMes to ("DMGファイルを選んでください") as text
037set strPrompt to ("DMGファイルを選んでください") as text
038try
039  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
040on error
041  log "エラーしました"
042  return "エラーしました"
043end try
044
045set strFilePath to (POSIX path of aliasFilePath) as text
046set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
047set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
048set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
049set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
050set strBaseFileName to (ocidBaseFilePathURL's lastPathComponent()) as text
051set ocidFileName to ocidFilePathURL's lastPathComponent()
052set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
053set strSetDirName to (strBaseFileName & "_読取専用")
054set ocidSaveDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strSetDirName) isDirectory:(true)
055set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
056ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
057set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
058set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)
059set strSaveFilePath to ocidSaveFilePathURL's |path| as text
060
061#読取専用へ
062set strCommandText to ("/bin/zsh -c '/usr/bin/hdiutil convert \"" & strFilePath & "\" -format UDRO   -o \"" & strSaveFilePath & "\"'") as text
063#読書可
064#set strCommandText to ("/bin/zsh -c '/usr/bin/hdiutil convert \"" & strFilePath & "\" -format UDRW   -o \"" & strSaveFilePath & "\"'") as text
065log strCommandText
066try
067  log (do shell script strCommandText) as text
068on error
069  return "コマンドエラー"
070end try
071
AppleScriptで生成しました

書き込み可能に
AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "UniformTypeIdentifiers"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015
016#############################
017###ダイアログを前面に出す
018set strName to (name of current application) as text
019if strName is "osascript" then
020  tell application "Finder" to activate
021else
022  tell current application to activate
023end if
024############ デフォルトロケーション
025set appFileManager to refMe's NSFileManager's defaultManager()
026set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
027set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
028set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
029tell application "Finder"
030  set aliasDefaultLocation to container of (path to me) as alias
031  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
032end tell
033
034############UTIリスト
035set listUTI to {"com.apple.disk-image-udif"}
036set strMes to ("DMGファイルを選んでください") as text
037set strPrompt to ("DMGファイルを選んでください") as text
038try
039  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
040on error
041  log "エラーしました"
042  return "エラーしました"
043end try
044
045set strFilePath to (POSIX path of aliasFilePath) as text
046set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
047set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
048set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
049set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
050set strBaseFileName to (ocidBaseFilePathURL's lastPathComponent()) as text
051set ocidFileName to ocidFilePathURL's lastPathComponent()
052set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
053set strSetDirName to (strBaseFileName & "_書込可")
054set ocidSaveDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strSetDirName) isDirectory:(true)
055set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
056ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
057set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
058set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)
059set strSaveFilePath to ocidSaveFilePathURL's |path| as text
060
061#読取専用へ
062#set strCommandText to ("/bin/zsh -c '/usr/bin/hdiutil convert \"" & strFilePath & "\" -format UDRO   -o \"" & strSaveFilePath & "\"'") as text
063#読書可
064set strCommandText to ("/bin/zsh -c '/usr/bin/hdiutil convert \"" & strFilePath & "\" -format UDRW   -o \"" & strSaveFilePath & "\"'") as text
065log strCommandText
066try
067  log (do shell script strCommandText) as text
068on error
069  return "コマンドエラー"
070end try
071
AppleScriptで生成しました

|

[bluray]VLCのブルーレイ再生ライブラリのインストール(3.0.20対応)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

####ARM版では動作しないので留意 VLC インテル版
###set strUrlVlcArm to "https://vlc.letterboxdelivery.org/vlc/3.0.17.3/macosx/vlc-3.0.17.3-arm64.dmg"
##set strUrlVlcIntel to "https://vlc.letterboxdelivery.org/vlc/3.0.17.3/macosx/vlc-3.0.17.3-intel64.dmg"
set strUrlVlcIntel to "https://free.nchc.org.tw/vlc/vlc/3.0.20/macosx/vlc-3.0.20-intel64.dmg"
###AACライブラリ
set strUrlLibaacs to "https://vlc-bluray.whoknowsmy.name/files/mac/libaacs.dylib"
##キーDB
set strUrlKeydb to "http://fvonline-db.bplaced.net/export/keydb_jpn.zip"


#########################################
###ユーザーアプリケーションフォルダを作る
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidApplicationDirPathURL to ocidURLsArray's firstObject()
set ocidAppDirPathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:("Movies/VLC_intel")
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidAppDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
if (item 1 of listBoolMakeDir) is false then
log "フォルダ作成でエラーしました"
return "フォルダ作成でエラーしました"
end if
#########################################
###ユーザーaacs Cachesフォルダを作る
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSCachesDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidCachesDirPathURL to ocidURLsArray's firstObject()
set ocidAacsCachesPathURL to ocidCachesDirPathURL's URLByAppendingPathComponent:"aacs"
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidAacsCachesPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
if (item 1 of listBoolMakeDir) is false then
log "フォルダ作成でエラーしました"
return "フォルダ作成でエラーしました"
end if
#########################################
###ユーザーbluray Cachesフォルダを作る
set ocidBlurayCachesPathURL to ocidCachesDirPathURL's URLByAppendingPathComponent:"bluray"
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidBlurayCachesPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
if (item 1 of listBoolMakeDir) is false then
log "フォルダ作成でエラーしました"
return "フォルダ作成でエラーしました"
end if
#########################################
###初期設定フォルダを作る
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
set ocidPreferencesDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/aacs")
set strPreferencesDirPath to ocidPreferencesDirPathURL's |path| as text
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidPreferencesDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
if (item 1 of listBoolMakeDir) is false then
log "フォルダ作成でエラーしました"
return "フォルダ作成でエラーしました"
end if
#########################################
####ダウンロードフォルダ
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
if (item 1 of listBoolMakeDir) is false then
log "フォルダ作成でエラーしました"
return "フォルダ作成でエラーしました"
end if
set strSaveDir to ocidSaveDirPathURL's |path| as text
#########################################
###vlcファイルのダウンロード
set objSysInfo to system info
set strCpuType to (CPU type of objSysInfo) as text
set strVlcSaveFilePath to (strSaveDir & "/vlc.dmg") as text
if strCpuType contains "Intel" then
  set strCommandText to "/usr/bin/curl -k \"" & strUrlVlcIntel & "\" -o \"" & strVlcSaveFilePath & "\" --connect-timeout 120" as text
else
  set strCommandText to "/usr/bin/curl -l \"" & strUrlVlcIntel & "\" -o \"" & strVlcSaveFilePath & "\" --connect-timeout 120" as text
end if
###コマンド実行
log "VLCダウンロード開始"
do shell script strCommandText
log "VLCダウンロード終了"

#########################################
###libaacs.dylibファイルのダウンロード
set strAacsSaveFilePath to (strSaveDir & "/libaacs.dylib.bin") as text
set strCommandText to "/usr/bin/curl -k \"" & strUrlLibaacs & "\" -o \"" & strAacsSaveFilePath & "\" --connect-timeout 120" as text
###コマンド実行
log "libaacs.dylibダウンロード開始"
do shell script strCommandText
log "libaacs.dylibダウンロード終了"

#########################################
###keydb_jpnファイルのダウンロード
set strKeySaveFilePath to (strSaveDir & "/keydb_jpn.zip") as text
set strCommandText to "/usr/bin/curl -k \"" & strUrlKeydb & "\" -o \"" & strKeySaveFilePath & "\" --connect-timeout 480" as text
###コマンド実行
log "keydb_jpn.zipダウンロード開始"
try
do shell script strCommandText
on error
  set strUrlKeydb to "https://force4u.cocolog-nifty.com/skywalker/files/keydb_jpn.zip"
  set strCommandText to "/usr/bin/curl -k \"" & strUrlKeydb & "\" -o \"" & strKeySaveFilePath & "\" --connect-timeout 480" as text
do shell script strCommandText
end try
log "keydb_jpn.zipダウンロード終了"


#########################################
###ユーザーアプリケーションフォルダにVLC.appがあればゴミ箱へ入れる
set ocidVclPathURL to ocidAppDirPathURL's URLByAppendingPathComponent:"VLC.app"
set strVclAppPath to ocidVclPathURL's |path| as text
##ゴミ箱に入れる
set boolGoToTrash to appFileManager's trashItemAtURL:(ocidVclPathURL) resultingItemURL:(ocidVclPathURL) |error|:(reference)
#########################################
###VLCをコピー
try
  set strCommandText to ("/usr/bin/hdiutil attach \"" & strVlcSaveFilePath & "\" -noverify -nobrowse -noautoopen\n") as text
do shell script strCommandText
on error
log "attachでエラーになりました"
return
end try
try
  set theComandText to ("/usr/bin/ditto \"/Volumes/VLC media player/VLC.app\" \"" & strVclAppPath & "\"") as text
do shell script theComandText
on error
log "dittoでエラーになりました"
return
end try
try
  set theComandText to ("/usr/bin/hdiutil detach \"Volumes/VLC media player\" -force") as text
do shell script theComandText
on error
log "detachでエラーになりました"
return
end try
#########################################
###libaacs.dylibを指定の場所にコピー
set ocidAacsSavePathURL to ocidVclPathURL's URLByAppendingPathComponent:"Contents/MacOS/lib/libaacs.dylib"
set strAacsSavePath to ocidAacsSavePathURL's |path| as text
try
  set theComandText to ("/usr/bin/ditto \"" & strAacsSaveFilePath & "\" \"" & strAacsSavePath & "\"") as text
do shell script theComandText
on error
log "libaacs.dylib dittoでエラーになりました"
return
end try
#########################################
### keydb.cfg まずは解凍してからコピー
try
  set theComandText to ("/usr/bin/unzip \"" & strKeySaveFilePath & "\" -d \"" & strSaveDir & "\"") as text
do shell script theComandText
on error
log "unzipでエラーになりました"
return
end try
set strUnzipPath to (strSaveDir & "/keydb.cfg") as text
try
  set theComandText to ("/usr/bin/ditto \"" & strUnzipPath & "\" \"" & strPreferencesDirPath & "/keydb.cfg\"") as text
  
do shell script theComandText
on error
log "keydb.cfg dittoでエラーになりました"
return
end try

#########################################
#アトリビュートをリセット
set theComandText to ("xattr -rc \"" & strVclAppPath & "\"") as text
do shell script theComandText
#########################################
#インストール先を表示
set ocidAppPathURL to ocidAppDirPathURL's URLByAppendingPathComponent:("VLC.app")
set ocidAppPath to ocidAppPathURL's |path|
set ocidContainerDirPath to ocidAppDirPathURL's |path|
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set boolDone to appSharedWorkspace's selectFile:(ocidAppPath) inFileViewerRootedAtPath:(ocidContainerDirPath)
set boolDone to appSharedWorkspace's openURL:(ocidAppPathURL)
if (boolDone as boolean) is false then
  #ファイルを開く
  set aliasSaveFilePath to (ocidAppDirPathURL's absoluteURL()) as alias
  tell application "Finder"
open file aliasSaveFilePath
  end tell
end if




|

[DMG]ディスクイメージを作る 4 File2DMGwPW


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 書き出す…からアプリケーションで書き出せば ドロップレットとしても使えます
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application

on run
  #############################
  ###【起動処理】Wクリックした場合 スクリプトから実行した場合
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###ダイアログ
  tell current application
    set strName to name as text
  end tell
  ###スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ### デフォルトロケーション
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
  set ocidFontsDirPathURL to (ocidLibraryDirPathURL's URLByAppendingPathComponent:("Fonts") isDirectory:true)
  set aliasDefaultLocation to (ocidFontsDirPathURL's absoluteURL()) as alias
  ###ダイアログ
  set strMes to "選択したファイルをDMGイメージファイルに変換します。"
  set strPrompt to "選択したファイルをDMGイメージファイルに変換します。"
  set listUTI to {"public.item"}
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
open listAliasFilePath
  
end run



on open listAliasFilePath
  #############################
  ###【事前処理】 最終的にゴミ箱に入れるテンポラリフォルダの制定
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
  ###フォルダを作る
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  # 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  
  ###エリアスの数だけ繰り返し
  repeat with itemAliasFilePath in listAliasFilePath
    #############################
    ###【1】 入力パス
    set aliasFilePath to itemAliasFilePath as alias
    set strFilePath to (POSIX path of aliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true)
    
    #############################
    ###【2】ファイル の場合 とフォルダの場合の
    ###ファイルがドロップされた場合対応
    set listBoolIsDir to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
    ###分岐
    if (item 2 of listBoolIsDir) = (refMe's NSNumber's numberWithBool:false) then
      log "ファイルの場合"
      set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
      set ocidBaseFileName to ocidBaseFilePathURL's lastPathComponent()
      set strDMGname to ((ocidBaseFileName as text) & ".dmg") as text
      set strDmgVolumeName to ocidBaseFileName as text
      set strFolderName to ocidBaseFileName as text
      set strDistName to (ocidFilePathURL's lastPathComponent()) as text
    else
      ###フォルダの場合
      ###フォルダの名前
      set recordFileInfo to info for aliasFilePath
      set strFolderName to (name of recordFileInfo) as text
      set strDMGname to (strFolderName & ".dmg") as text
      set strDmgVolumeName to strFolderName as text
      set strDistName to strFolderName as text
    end if
    
    #############################
    ###【3】テンポラリー内のDMGの本体になるフォルダ
    ###DMGになるフォルダ保存パス
    set ocidMakeTmpDirPathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strFolderName) isDirectory:true)
    ###コマンド用のパス
    set strMakeDmgDirPath to ocidMakeTmpDirPathURL's |path| as text
    ###フォルダを作る
    set listDone to (appFileManager's createDirectoryAtURL:(ocidMakeTmpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
    
    ################################
    ####【4】最終的にDMGを移動するディレクトリ
    #### 暗号化DMGの保存先
    set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
    set strFinishedDirName to (strFolderName & "_暗号化済DMG") as text
    set ocidFinishedDirPathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:(strFinishedDirName))
    ###フォルダを作る
    set listDone to (appFileManager's createDirectoryAtURL:(ocidFinishedDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
    ###Finder用
    set aliasOpenDirPath to (ocidFinishedDirPathURL's absoluteURL()) as alias
    
    #############################
    ###【5】最終的にDMGを移動するパス
    set ocidMoveDmgPathURL to (ocidFinishedDirPathURL's URLByAppendingPathComponent:(strDMGname))
    set strMoveDmgPath to (ocidMoveDmgPathURL's |path|()) as text
    
    ########################################
    ###【6】パスワード生成 UUIDを利用
    ###生成したUUIDからハイフンを取り除く
    set ocidUUIDString to (refMe's NSMutableString's alloc()'s initWithCapacity:0)
    set ocidConcreteUUID to refMe's NSUUID's UUID()
(ocidUUIDString's setString:(ocidConcreteUUID's UUIDString()))
    set ocidUUIDRange to (ocidUUIDString's rangeOfString:ocidUUIDString)
(ocidUUIDString's replaceOccurrencesOfString:("-") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidUUIDRange)
    set strOwnerPassword to ocidUUIDString as text
    ########################################
    ###【6】 パスワードファイル生成保存
    set strPWFileName to strDMGname & ".PW.txt"
    set ocidPWFilePathURL to (ocidFinishedDirPathURL's URLByAppendingPathComponent:(strPWFileName))
    ###テキスト
    set strTextFile to "先にお送りしました圧縮ファイル\n『" & strDMGname & "』の\n解凍パスワードをお知らせします\n\n" & strOwnerPassword & "\n\n解凍出来ない等ありましたらお知らせください。\n(パスワードをコピー&ペーストする際に\n改行やスペースが入らないように留意ください)\n" as text
    set ocidPWString to (refMe's NSString's stringWithString:(strTextFile))
    set ocidUUIDData to (ocidPWString's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
    #####パスワードを書いたテキストファイルを保存
    set boolResults to (ocidUUIDData's writeToURL:(ocidPWFilePathURL) atomically:true)
    
    #############################
    ###【7】3で生成したフォルダに1の内容をコピーするためのURL
    ###元フォルダをコピーする先のURL
    set ocidCopyItemDirPathURL to (ocidMakeTmpDirPathURL's URLByAppendingPathComponent:(strDistName) isDirectory:true)
    ###元ディレクトリをコピーする
    set listDone to (appFileManager's copyItemAtURL:(ocidFilePathURL) toURL:(ocidCopyItemDirPathURL) |error|:(reference))
    
    #############################
    ###【8】コマンド生成するDMGのパス
    set ocidDmgPathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strDMGname) isDirectory:false)
    set strDmgPath to (ocidDmgPathURL's |path|()) as text
    
    ###
    delay 1
    #############################
    ###【9】コマンド実行 DMG生成
    
    ###読み取り専用でDMG作成
    set strCommandText to ("hdiutil create -volname \"" & strDmgVolumeName & "\" -srcfolder \"" & strMakeDmgDirPath & "\" -ov -format UDRO \"" & strDmgPath & "\"") as text
    
    log strCommandText
    do shell script strCommandText
    ########################################
    ###【10】4のURLに生成されたDMGファイルを 6のURLに移動する
    ###その時に生成したパスワードで暗号化する
    ###旧仕様
    set strCommandText to ("/usr/bin/hdiutil convert \"" & strDmgPath & "\" -format UDRO -o \"" & strMoveDmgPath & "\" -encryption AES-128 -passphrase " & strOwnerPassword & "") as text
    ###現行仕様
    set strCommandText to ("/usr/bin/printf " & strOwnerPassword & " | /usr/bin/hdiutil convert \"" & strDmgPath & "\" -format UDRO -o \"" & strMoveDmgPath & "\" -encryption AES-128 -stdinpass") as text
    log strCommandText
    
do shell script strCommandText
    
  end repeat
  ####DMG作成処理が終わったら
  ###保存先を開く
  (*
tell application "Finder"
open aliasOpenDirPath
end tell
*)
  ########################################
  ###【11】保存先を開く
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set boolDone to appSharedWorkspace's selectFile:(ocidMoveDmgPathURL's |path|()) inFileViewerRootedAtPath:(ocidFinishedDirPathURL's |path|())
  
  ########################################
  ###【12】中間ファイルをゴミ箱に
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSTrashDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidTrashURL to ocidURLsArray's firstObject()
  set ocidMoveTrashDirURL to (ocidTrashURL's URLByAppendingPathComponent:(strFolderName) isDirectory:true)
  set listDone to appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidMoveTrashDirURL) |error|:(reference)
  
  
  
end open





|

[DMG]ディスクイメージを作る 3 File2DMG


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 書き出す…からアプリケーションで書き出せば ドロップレットとしても使えます
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application

on run
  #############################
  ###【起動処理】Wクリックした場合 スクリプトから実行した場合
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###ダイアログ
  tell current application
    set strName to name as text
  end tell
  ###スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  ### デフォルトロケーション
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
  set ocidFontsDirPathURL to (ocidLibraryDirPathURL's URLByAppendingPathComponent:("Fonts") isDirectory:true)
  set aliasDefaultLocation to (ocidFontsDirPathURL's absoluteURL()) as alias
  ###ダイアログ
  set strMes to "選択したファイルをDMGイメージファイルに変換します。"
  set strPrompt to "選択したファイルをDMGイメージファイルに変換します。"
  set listUTI to {"public.item"}
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
open listAliasFilePath
  
end run



on open listAliasFilePath
  #############################
  ###【事前処理】 最終的にゴミ箱に入れるテンポラリフォルダの制定
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
  ###フォルダを作る
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  # 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  
  ###エリアスの数だけ繰り返し
  repeat with itemAliasFilePath in listAliasFilePath
    #############################
    ###【1】 入力パス
    set aliasFilePath to itemAliasFilePath as alias
    set strFilePath to (POSIX path of aliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true)
    
    #############################
    ###【2】ファイル の場合 とフォルダの場合の
    ###ファイルがドロップされた場合対応
    set listBoolIsDir to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
    ###分岐
    if (item 2 of listBoolIsDir) = (refMe's NSNumber's numberWithBool:false) then
      log "ファイルの場合"
      set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
      set ocidBaseFileName to ocidBaseFilePathURL's lastPathComponent()
      set strDMGname to ((ocidBaseFileName as text) & ".dmg") as text
      set strDmgVolumeName to ocidBaseFileName as text
      set strFolderName to ocidBaseFileName as text
      set strDistName to (ocidFilePathURL's lastPathComponent()) as text
    else
      ###フォルダの場合
      ###フォルダの名前
      set recordFileInfo to info for aliasFilePath
      set strFolderName to (name of recordFileInfo) as text
      set strDMGname to (strFolderName & ".dmg") as text
      set strDmgVolumeName to strFolderName as text
      set strDistName to strFolderName as text
    end if
    
    #############################
    ###【3】テンポラリー内のDMGの本体になるフォルダ
    ###DMGになるフォルダ保存パス
    set ocidMakeTmpDirPathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strFolderName) isDirectory:true)
    ###コマンド用のパス
    set strMakeDmgDirPath to ocidMakeTmpDirPathURL's |path| as text
    ###フォルダを作る
    set listDone to (appFileManager's createDirectoryAtURL:(ocidMakeTmpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
    
    #############################
    ###【4】最終的にDMGを移動するパス
    ###元ディレクトリのコンテナ
    set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
    set aliasContainerDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
    ###DMGのURL
    set ocidMoveDmgPathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:(strDMGname) isDirectory:false)
    
    #############################
    ###【5】3で生成したフォルダに1の内容をコピーするためのURL
    ###元フォルダをコピーする先のURL
    set ocidCopyItemDirPathURL to (ocidMakeTmpDirPathURL's URLByAppendingPathComponent:(strDistName) isDirectory:true)
    ###元ディレクトリをコピーする
    set listDone to (appFileManager's copyItemAtURL:(ocidFilePathURL) toURL:(ocidCopyItemDirPathURL) |error|:(reference))
    
    #############################
    ###【6】コマンド生成するDMGのパス
    set ocidDmgPathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strDMGname) isDirectory:false)
    set strDmgPath to (ocidDmgPathURL's |path|()) as text
    
    ###
    delay 1
    #############################
    ###【7】コマンド実行
    (*
■■■フォーマットオプションについて
"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"
"UNIV:HFS+/ISO/UDF"
"SPARSEBUNDLE:SPARSEBUNDLE"
"SPARSE:SPARSE Disk image"
"UDIF:read/write"

set strCommandText to ("hdiutil create -volname \"" & strDmgVolumeName & "\" -srcfolder \"" & strMakeDmgDirPath & "\" -ov -format XXXXXXXXXX \"" & strDmgPath & "\"") as text

■■■ファイルシステムを指定する場合
"HFS+:通常拡張"
"HFS+J:ジャーナリング"
"HFSX:大小文字判別"
"JHFS+X:ジャーナリング大小文字判別"
"APFS:現行macOS10.13以上"
"Case-sensitive APFS:APFS大小文字判別"
"MS-DOS:Windows互換汎用FAT"
"MS-DOS FAT12:Windows互換汎用FAT12"
"MS-DOS FAT16:Windows互換汎用FAT16"
"FAT32:Windows互換汎用"
"ExFAT:Windows互換推奨"
"UDF:ディスクマスター用"

set strCommandText to ("hdiutil create -volname \"" & strDmgVolumeName & "\" -srcfolder \"" & strMakeDmgDirPath & "\" -ov -format UDRO -fs XXXXXXXXXXXX -layout 'MBRSPUD' \"" & strDmgPath & "\"") as text

*)
    
    ###読み取り専用
    set strCommandText to ("hdiutil create -volname \"" & strDmgVolumeName & "\" -srcfolder \"" & strMakeDmgDirPath & "\" -ov -format UDRO \"" & strDmgPath & "\"") as text
    
    
    log strCommandText
    do shell script strCommandText
    
    ###【8】4のURLに生成されたDMGファイルを 6のURLに移動する
    set listDone to (appFileManager's moveItemAtURL:(ocidDmgPathURL) toURL:(ocidMoveDmgPathURL) |error|:(reference))
    
    
  end repeat
  ####DMG作成処理が終わったら
  ###保存先を開く
  (*
tell application "Finder"
open aliasContainerDirPath
end tell
*)
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set boolDone to appSharedWorkspace's selectFile:(ocidMoveDmgPathURL's |path|()) inFileViewerRootedAtPath:(ocidContainerDirPathURL's |path|())
  
  ####中間ファイルをゴミ箱に
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSTrashDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidTrashURL to ocidURLsArray's firstObject()
  set ocidMoveTrashDirURL to (ocidTrashURL's URLByAppendingPathComponent:(strFolderName) isDirectory:true)
  set listDone to appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidMoveTrashDirURL) |error|:(reference)
  
  
  
end open





|

[DMG]ディスクイメージを作る 2 Folder2FolderInDMG


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 書き出す…からアプリケーションで書き出せば ドロップレットとしても使えます
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application

on run
  ### ダブルクリックしたら スクリプトから実行したら
  set strMes to "選択したフォルダをDMGイメージファイルに変換します。"
  set aliasDefaultLocation to (path to fonts folder from user domain) as alias
  set listAliasDirPath to (choose folder strMes default location aliasDefaultLocation with prompt strMes with invisibles and multiple selections allowed without showing package contents) as list
open listAliasDirPath
  
end run



on open listAliasDirPath
  #####【事前処理】最終的にゴミ箱に入れるフォルダを作る
  ###テンポラリ
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
  ###フォルダを作る
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  # 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  
  ###エリアスの数だけ繰り返し
  repeat with itemAliasDirPath in listAliasDirPath
    ###【1】入力フォルダパス
    set aliasDirPath to itemAliasDirPath as alias
    set strDirPath to (POSIX path of aliasDirPath) as text
    set ocidDirPathStr to (refMe's NSString's stringWithString:(strDirPath))
    set ocidDirPath to ocidDirPathStr's stringByStandardizingPath()
    set ocidDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPath) isDirectory:true)
    ###ファイルがドロップされた場合対応
    set listBoolIsDir to (ocidDirPathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
    if (item 2 of listBoolIsDir) = (refMe's NSNumber's numberWithBool:false) then
      log "ディレクトリ以外は処理しません"
      display alert "ディレクトリ以外は処理しません"
return "ディレクトリ以外は処理しません"
      exit repeat
    end if
    
    ###フォルダの名前
    set recordFileInfo to info for aliasDirPath
    set strFolderName to (name of recordFileInfo) as text
    set strDMGname to (strFolderName & ".dmg") as text
    
    ###【2】入力フォルダのコンテナディレクトリ
    set ocidContainerDirPathURL to ocidDirPathURL's URLByDeletingLastPathComponent()
    set aliasContainerDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
    
    ###【3】最終的に出来上がったDMGファイルを移動させるパス
    ###DMGになるフォルダ保存パス
    set ocidMoveDmgPathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:(strDMGname) isDirectory:false)
    
    ###【4】テンポラリ内でDMGファイルを生成するパス
    ###DMGを作成するURL
    set ocidDmgPathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strDMGname) isDirectory:false)
    ###コマンド用のパス
    set strDmgPath to ocidDmgPathURL's |path| as text
    
    ###【5】テンポラリ内 DMGの本体となるディレクトリ 
    ###DMGになるフォルダ
    set ocidMakeTmpDirPathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strFolderName) isDirectory:false)
    ###コマンド用のパス
    set strMakeDmgDirPath to ocidMakeTmpDirPathURL's |path| as text
    ###フォルダを作る
    set listDone to (appFileManager's createDirectoryAtURL:(ocidMakeTmpDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
    ###【6】↑5で作ったフォルダ内に1のフォルダをコピーするためのパス
    ###元フォルダをコピーする先のURL
    set ocidCopyItemDirPathURL to (ocidMakeTmpDirPathURL's URLByAppendingPathComponent:(strFolderName) isDirectory:true)
    ###【7】1のURLを6のURLにコピーする
    set listDone to (appFileManager's copyItemAtURL:(ocidDirPathURL) toURL:(ocidCopyItemDirPathURL) |error|:(reference))
    ###
    delay 1
    ###【8】コマンド整形して実行
    set strCommandText to ("/usr/bin/hdiutil create -volname \"" & strFolderName & "\" -srcfolder \"" & strMakeDmgDirPath & "\" -ov -format UDRO \"" & strDmgPath & "\"") as text
    log strCommandText
    do shell script strCommandText
    delay 1
    ###【9】4のURLに生成されたDMGファイルを 3のURLに移動する
    set listDone to (appFileManager's moveItemAtURL:(ocidDmgPathURL) toURL:(ocidMoveDmgPathURL) |error|:(reference))
    
  end repeat
  ####DMG作成処理が終わったら
  ###保存先を開く
  tell application "Finder"
    open aliasContainerDirPath
  end tell
  
  ####【10】事前処理で作ったフォルダをゴミ箱に入れる
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSTrashDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidTrashURL to ocidURLsArray's firstObject()
  set ocidMoveTrashDirURL to (ocidTrashURL's URLByAppendingPathComponent:(strFolderName) isDirectory:true)
  set listDone to appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidMoveTrashDirURL) |error|:(reference)
return "処理終了"
end open





|

[DMG]ディスクイメージを作る 1 Folder2DMG


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 書き出す…からアプリケーションで書き出せば ドロップレットとしても使えます
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

on run
  set strMes to "選択したフォルダをDMGイメージファイルに変換します。"
  set aliasDefaultLocation to (path to fonts folder from user domain) as alias
  set listAliasDirPath to (choose folder strMes default location aliasDefaultLocation with prompt strMes with invisibles and multiple selections allowed without showing package contents) as list
open listAliasDirPath
end run



on open listAliasDirPath
  ###エリアスの数だけ繰り返し
  repeat with itemAliasDirPath in listAliasDirPath
    ###入力パス
    set aliasDirPath to itemAliasDirPath as alias
    set strDirPath to (POSIX path of aliasDirPath) as text
    ###フォルダの名前
    set recordFileInfo to info for aliasDirPath
    set strFolderName to (name of recordFileInfo) as text
    log recordFileInfo
    if (kind of recordFileInfo) is "フォルダ" then
      ##そのまま処理
    else if (kind of recordFileInfo) is folder then
      ##そのまま処理
    else
      log "ディレクトリ以外は処理しません"
      display alert "ディレクトリ以外は処理しません"
return "ディレクトリ以外は処理しません"
      exit repeat
    end if
return
    ###選んだフォルダのコンテナ
    tell application "Finder"
      set aliasContainerDirPath to (container of aliasDirPath) as alias
    end tell
    ###DMGの名前
    set strDirName to (strFolderName & ".dmg")
    ###出力パス
    set strContainerDirPath to (POSIX path of aliasContainerDirPath) as text
    set strSaveFilePath to (strContainerDirPath & strDirName) as text
    ###コマンド実行
    set strCommandText to ("hdiutil create -volname \"" & strFolderName & "\" -srcfolder \"" & strDirPath & "\" -ov -format UDRO \"" & strSaveFilePath & "\"") as text
    log strCommandText
    do shell script strCommandText
  end repeat
  
  ###保存先を開く
  tell application "Finder"
    open aliasContainerDirPath
  end tell
  
end open





|

[dmg]ディスクイメージ(背景付・VolumeIcon付)暗号化+パスワード設定

ダウンロード - dmgwpw.zip

|

ボリュームをアンマウント


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions


property refMe : a reference to current application


###初期化
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
set appFileManager to refMe's NSFileManager's defaultManager()
####bool値を定義
set boolTrue to refMe's NSNumber's numberWithBool:true
set boolFalse to refMe's NSNumber's numberWithBool:false
#############################################
###ボリュームリストを取得
set ocidResourceArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
ocidResourceArray's addObject:(refMe's NSURLVolumeIsRemovableKey)
ocidResourceArray's addObject:(refMe's NSURLVolumeIsInternalKey)
ocidResourceArray's addObject:(refMe's NSURLVolumeIsEjectableKey)
ocidResourceArray's addObject:(refMe's NSURLVolumeIsLocalKey)
set ocidDriveListArray to appFileManager's mountedVolumeURLsIncludingResourceValuesForKeys:(ocidResourceArray) options:(refMe's NSVolumeEnumerationSkipHiddenVolumes)

#############################################
###ボリュームのURLの数だけ繰り返し
##外付けでイジェクト可能なドライブリストを格納する
set ocidDriveLisArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
####
repeat with itemDriveURL in ocidDriveListArray
  ###キーを取り出して
  set listResDict to (itemDriveURL's resourceValuesForKeys:(ocidResourceArray) |error|:(reference))
  set ocidResourceValuesDict to item 1 of listResDict
  ###内臓ドライブか?
  set boolIsInternal to (ocidResourceValuesDict's objectForKey:(refMe's NSURLVolumeIsInternalKey))
  ###ローカルデバイスか? true でローカル falseでネットワークドライブ
  set boolLocal to (ocidResourceValuesDict's objectForKey:(refMe's NSURLVolumeIsLocalKey))
  ###外付けで
  if boolIsInternal = boolFalse then
    ##対象に加える
(ocidDriveLisArrayM's addObject:(itemDriveURL's |path|() as text))
    ###リムーバブル=USBメモリー等か
    set boolRemovable to (ocidResourceValuesDict's objectForKey:(refMe's NSURLVolumeIsRemovableKey))
    if boolRemovable = boolTrue then
      # log "リムーバブル=USBメモリー"
    end if
    ###イジェクト=排出可能か? ※アンマウント出来るとは違う
    set boolEjectable to (ocidResourceValuesDict's objectForKey:(refMe's NSURLVolumeIsEjectableKey))
    if boolEjectable = boolTrue then
      # log "イジェクト可能=CD/DVDやUSBメモリ"
    end if
    ###ネットワークドライブ
  else if boolLocal = boolFalse then
    ##対象に加える
(ocidDriveLisArrayM's addObject:(itemDriveURL's |path|() as text))
  end if
end repeat

#############################################
###ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###ダイアログ用にリストに
set listDriveList to ocidDriveLisArrayM as list

try
  tell current application
    activate
    set listResponse to (choose from list listDriveList with title "選んでください" with prompt "アンマウントします" default items (item 1 of listDriveList) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed and empty selection allowed) as list
  end tell
on error
  log "エラーしました"
return "エラーしました"
  error "エラーしました" number -200
end try
if (count of listResponse) = 0 then
  log "選択無しの場合の処理"
return "選択無しでした"
else if (item 1 of listResponse) is false then
return "キャンセルしました"
  error "キャンセルしました" number -200
end if

###ボリュームの数だけ繰り返し
repeat with itemResponse in listResponse
  ###NSURLにする
  set ocidFilePath to (refMe's NSString's stringWithString:(itemResponse))
  set ocidFilePath to ocidFilePath's stringByStandardizingPath
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  set ocidResulut to (appSharedWorkspace's unmountAndEjectDeviceAtURL:(ocidFilePathURL) |error|:(reference))
  if (item 1 of ocidResulut) = false then
doGetErrorData(item 2 of ocidResulut) as list
  end if
end repeat

to doGetErrorData(ocidNSErrorData)
  #####個別のエラー情報
  log "エラーコード:" & ocidNSErrorData's code() as text
  log "エラードメイン:" & ocidNSErrorData's domain() as text
  set strMes to ("Description:" & ocidNSErrorData's localizedDescription()) as text
  if strMes contains "-47" then
    set strMes to "使用中のファイルがあります\r" & strMes
    display alert strMes
  else
    display alert strMes
  end if
  log "FailureReason:" & ocidNSErrorData's localizedFailureReason() as text
  log ocidNSErrorData's localizedRecoverySuggestion() as text
  log ocidNSErrorData's localizedRecoveryOptions() as text
  log ocidNSErrorData's recoveryAttempter() as text
  log ocidNSErrorData's helpAnchor() as text
  set ocidNSErrorUserInfo to ocidNSErrorData's userInfo()
  set ocidAllValues to ocidNSErrorUserInfo's allValues() as list
  set ocidAllKeys to ocidNSErrorUserInfo's allKeys() as list
  repeat with ocidKeys in ocidAllKeys
    if (ocidKeys as text) is "NSUnderlyingError" then
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedDescription() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedFailureReason() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedRecoverySuggestion() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s localizedRecoveryOptions() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s recoveryAttempter() as text
      log (ocidNSErrorUserInfo's valueForKey:ocidKeys)'s helpAnchor() as text
    else
      ####それ以外の値はそのままテキストで読める
      log (ocidKeys as text) & ": " & (ocidNSErrorUserInfo's valueForKey:ocidKeys) as text
    end if
  end repeat
  
end doGetErrorData


|

クラウドドライブをFinderで開く AdobeCCを追加


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
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()
##CloudStorageのURL
set ocidUserLibraryPathArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserLibraryPathURL to ocidUserLibraryPathArray's objectAtIndex:0
set ocidCloudStorageURL to ocidUserLibraryPathURL's URLByAppendingPathComponent:"CloudStorage"
###プロパティ設定
set ocidPropertieKey to {(refMe's NSURLPathKey), (refMe's NSURLIsDirectoryKey)}
###オプション設定
set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles
###ディレクトリのコンテンツを取得(第一階層のみ)
set listPathUrlArray to (appFileManager's contentsOfDirectoryAtURL:ocidCloudStorageURL includingPropertiesForKeys:ocidPropertieKey options:ocidOption |error|:(reference))
set ocidPathArray to item 1 of listPathUrlArray
####################################
##ディレクトリ名を取得
####################################
set listDirName to {"iCloud Drive"} as list

##AdobeCC利用中かチェックする
set ocidHomeDirPathURL to appFileManager's homeDirectoryForCurrentUser()
set ocidChkDirPathURL to ocidHomeDirPathURL's URLByAppendingPathComponent:("Creative Cloud Files") isDirectory:true
set ocidChkDirPath to ocidChkDirPathURL's |path|()
set boolExistChk to appFileManager's fileExistsAtPath:(ocidChkDirPath) isDirectory:(true)
if boolExistChk is true then
  set end of listDirName to "Creative Cloud Files"
end if

##CloudStorageにあるディレクトリをリストに入れる
repeat with itemPathArray in ocidPathArray
  set ocidDirName to itemPathArray's lastPathComponent()
  set strDirName to ocidDirName as text
  set end of listDirName to strDirName
end repeat


####################################
##ダイアログ
####################################

###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
try
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder"
      activate
      set listResponse to (choose from list listDirName with title "選んでください" with prompt "クラウドストレージを開きます" default items (item 1 of listDirName) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
    end tell
  else
    ####スクリプトエディタから実行したら
    tell current application
      activate
      set listResponse to (choose from list listDirName with title "選んでください" with prompt "クラウドストレージを開きます" default items (item 1 of listDirName) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
    end tell
  end if
on error
  log "エラーしました"
return "エラーしました"
  error "エラーしました" number -200
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
  error "キャンセルしました" number -200
end if
####ワークスペース初期化
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
####ダイアログで選択した数だけ繰り返し
repeat with itemResponse in listResponse
  set strResponse to itemResponse as text
  ##別処理のための分岐
  if strResponse is "iCloud Drive" then
    ###URLにしてからパスに戻して
    set ocidiCloudFilePathURL to (ocidUserLibraryPathURL's URLByAppendingPathComponent:("Mobile Documents") isDirectory:true)
    set ocidiCloudFilePath to ocidiCloudFilePathURL's |path|()
    ###開く
(appSharedWorkspace's selectFile:(missing value) inFileViewerRootedAtPath:(ocidiCloudFilePath))
  else if strResponse is "Creative Cloud Files" then
    ###開く
(appSharedWorkspace's selectFile:(ocidChkDirPath) inFileViewerRootedAtPath:(ocidChkDirPath))
  else
    ###URLにしてからパスに戻して
    set ocidCloudStorageFilePathURL to (ocidCloudStorageURL's URLByAppendingPathComponent:(strResponse))
    set ocidCloudStorageFilePath to ocidCloudStorageFilePathURL's |path|()
    ###開く
(appSharedWorkspace's selectFile:(missing value) inFileViewerRootedAtPath:(ocidCloudStorageFilePath))
  end if
end repeat

###Finderを前面に
set strBundleID to "com.apple.finder" as text
set ocidRunningApplication to refMe's NSRunningApplication
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
set ocidApp to ocidAppArray's firstObject()
ocidApp's activateWithOptions:(refMe's NSApplicationActivateAllWindows)
repeat 10 times
  set boolActive to ocidApp's active
  if boolActive = (refMe's NSNumber's numberWithBool:true) then
    exit repeat
  else
    delay 0.5
    set boolDone to ocidApp's activateWithOptions:(refMe's NSApplicationActivateIgnoringOtherApps)
  end if
end repeat
return "処理終了"


|

その他のカテゴリー

Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager Apple AppleScript AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Audio AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Diff AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript Droplet AppleScript eMail AppleScript Encode % AppleScript Encode Decode AppleScript Encode UTF8 AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript Guide AppleScript HTML AppleScript HTML Entity AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim AppleScript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript Leading Zero AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript Mail AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Messages AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSArray Sort AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFileManager enumeratorAtURL AppleScript NSFont AppleScript NSFontManager AppleScript NSGraphicsContext AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSpoint AppleScript NSPredicate AppleScript NSPrintOperation AppleScript NSRange AppleScript NSRect AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSURLSession AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotation AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFImageRep AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photoshop AppleScript Pictures AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript Swift AppleScript System Events AppleScript System Events Plist AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text MD AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML savedSearch AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript XMP AppleScript YouTube Applications CityCode github iPhone List lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom Windows zoom