property refMe : a reference to current application
###【設定項目】バイナリーへのパス
set strImg2webpPath to ("~/bin/libwebp/bin/img2webp") as text
set strWebpinfoPath to ("~/bin/libwebp/bin/webpinfo") as text
###【設定項目】コマ間隔 1000=1秒
# (8コマ=125 10コマ=100 16コマ≒62 32コマ≒31)
set numDuration to 125 as number
###img2webpパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strImg2webpPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strImg2webpPath to ocidBinPath as string
###webpinfoパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strWebpinfoPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strWebpinfoPath to ocidBinPath as string
###ダイアログを前面に
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
tell application "Finder"
set aliasDesktopFolder to (path to desktop folder from user domain) as alias
end tell
####ファイル選択ダイアログ
set listAliasFilePath to (choose file with prompt "ファイルを選んでください" default location aliasDesktopFolder of type {"public.png"} with invisibles and multiple selections allowed without showing package contents) as list
###並び替え用のアレーの初期化
set ocidFilePathArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###選択したファイルパスをUNIXファイルパスに変換してリストに格納
repeat with itemAliasFilePath in listAliasFilePath
set aliasFilePath to itemAliasFilePath as alias
set strFilePath to (POSIX path of aliasFilePath) as text
(ocidFilePathArrayM's addObject:(strFilePath))
end repeat
####ファイルパスを名前順に並び替え
set ocidSortedArray to ocidFilePathArrayM's sortedArrayUsingSelector:("localizedStandardCompare:")
set numCntImage to (count of ocidSortedArray) as integer
###
#######
###ディレクトリ
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:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
##
set strTempPath to ocidSaveDirPathURL's |path| as text
set strSaveFilePath to (strTempPath & "/animetion.webp") as text
############################
####コマンド行の初期化
############################
set strCommandText to ("") as text
repeat with itemSortedArray in ocidSortedArray
set strFilePath to itemSortedArray as text
###コマンド行【入力ファイル部分】を整形して
set strAddCommandText to ("-lossless -d " & numDuration & " -q 100 \"" & strFilePath & "\"") as text
set strCommandText to (strCommandText & " " & strAddCommandText) as text
end repeat
############################
###コマンド行 出力部
############################
set strCommandText to ("\"" & strImg2webpPath & "\" " & strCommandText & " -o \"" & strSaveFilePath & "\"") as text
do shell script strCommandText
############################
###コマンドWebpinfo部
############################
set strCommandText to ("\"" & strWebpinfoPath & "\" \"" & strSaveFilePath & "\" | grep \"Canvas size\" | tr -d \"Canvas size\"") as text
set strResponse to (do shell script strCommandText) as text
############################
###コマンド行 Ditto部
############################
set strNewFileName to ("animation_" & numCntImage & "_" & strResponse & ".webp") as text
set strDesktopFolder to (POSIX path of aliasDesktopFolder) as text
set strDittoFilePath to (strDesktopFolder & strNewFileName) as text
set strCommandText to ("/usr/bin/ditto \"" & strSaveFilePath & "\" \"" & strDittoFilePath & "\"") as text
do shell script strCommandText
property refMe : a reference to current application
###【設定項目】バイナリーへのパス
set strImg2webpPath to ("~/bin/libwebp/bin/img2webp") as text
set strWebpinfoPath to ("~/bin/libwebp/bin/webpinfo") as text
###【設定項目】コマ間隔 1000=1秒
# (8コマ=125 10コマ=100 16コマ≒62 32コマ≒31)
set numDuration to125 as number
###img2webpパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strImg2webpPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strImg2webpPath to ocidBinPath as string
###webpinfoパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strWebpinfoPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strWebpinfoPath to ocidBinPath as string
###ダイアログを前面に
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
tell application "Finder"
set aliasDesktopFolder to (path to desktop folder from user domain) as alias
end tell
####ファイル選択ダイアログ
set listAliasFilePath to (choose file with prompt "ファイルを選んでください" default location aliasDesktopFolder of type {"public.png"} with invisibles and multiple selections allowed without showing package contents) as list
###並び替え用のアレーの初期化
set ocidFilePathArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###選択したファイルパスをUNIXファイルパスに変換してリストに格納
repeatwith itemAliasFilePath in listAliasFilePath
set aliasFilePath to itemAliasFilePath as alias
set strFilePath to (POSIX path of aliasFilePath) as text
(ocidFilePathArrayM's addObject:(strFilePath))
end repeat
####ファイルパスを名前順に並び替え
set ocidSortedArray to ocidFilePathArrayM's sortedArrayUsingSelector:("localizedStandardCompare:")
set numCntImage to (count of ocidSortedArray) as integer
###
#######
###ディレクトリ
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
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
##
set strTempPath to ocidSaveDirPathURL's |path| as text
set strSaveFilePath to (strTempPath & "/animetion.webp") as text
############################
####コマンド行の初期化
############################
set strCommandText to ("") as text
repeatwith itemSortedArray in ocidSortedArray
set strFilePath to itemSortedArray as text
###コマンド行【入力ファイル部分】を整形して
set strAddCommandText to ("-lossless -d " & numDuration & " -q 100 \"" & strFilePath & "\"") as text
set strCommandText to (strCommandText & " " & strAddCommandText) as text
end repeat
############################
###コマンド行 出力部
############################
set strCommandText to ("\"" & strImg2webpPath & "\" " & strCommandText & " -o \"" & strSaveFilePath & "\"") as text
do shell script strCommandText
############################
###コマンドWebpinfo部
############################
set strCommandText to ("\"" & strWebpinfoPath & "\" \"" & strSaveFilePath & "\" | grep \"Canvas size\" | tr -d \"Canvas size\"") as text
set strResponse to (do shell script strCommandText) as text
############################
###コマンド行 Ditto部
############################
set strNewFileName to ("animation_" & numCntImage & "_" & strResponse & ".webp") as text
set strDesktopFolder to (POSIX path of aliasDesktopFolder) as text
set strDittoFilePath to (strDesktopFolder & strNewFileName) as text
set strCommandText to ("/usr/bin/ditto \"" & strSaveFilePath & "\" \"" & strDittoFilePath & "\"") as text