#!/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