AppleScript webp

[anim_dump] アニメーションWEBPファイルから各フレームイメージを書き出す(フレームイメージ)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* libwebpが別途必要です
[applescript]libwebpインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-0a1a86.html

WEBPのアニメーションファイルからのイメージシーケンスの書き出しは
GIFと違って各フレームには
差分のみ保存されていますので あまり使いやすいものでもありません
*)
# 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 strAnim_dumpPath to ("~/bin/libwebp/bin/anim_dump") as text


###anim_dumpパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strAnim_dumpPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strAnim_dumpPath 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 aliasFilePath to (choose file with prompt "WEBPのアニメーションファイルを選んでください" default location aliasDesktopFolder of type {"org.webmproject.webp"} with invisibles without showing package contents and multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
##出力用のディレクトリを作る
tell application "Finder"
  set strInputFileName to (name of aliasFilePath) as text
  set strSaveDirName to (strInputFileName & "_フレーム画像") as text
  set aliasContainerDirPath to (container of aliasFilePath) as alias
make new folder at aliasContainerDirPath with properties {name:strSaveDirName}
  set aliasSaveDirPath to (folder strSaveDirName of folder aliasContainerDirPath) as alias
end tell
##出力用のディレクトリのパス
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text

############################
####anim_dump
############################
set strCommandText to ("\"" & strAnim_dumpPath & "\" -folder \"" & strSaveDirPath & "\" -prefix \"Flame_\" \"" & strFilePath & "\"") as text
set strResponse to (do shell script strCommandText) as text


|

[bash]libwebpインストール


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#ユーザー ~/binにインストールする

########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザーは:$USER_WHOAMI"
###実行しているユーザー名
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "コンソールユーザー:$CONSOLE_USER"
###ログイン名ユーザー名※Visual Studio Codeの出力パネルではrootになる設定がある
LOGIN_NAME=$(/usr/bin/logname)
/bin/echo "ログイン名:$LOGIN_NAME"
###UID
USER_NAME=$(/usr/bin/id -un)
/bin/echo "ユーザー名:$USER_NAME"
###SUDOUSER
/bin/echo "SUDO_USER: $SUDO_USER"
########################################
##OS
PLIST_PATH="/System/Library/CoreServices/SystemVersion.plist"
STR_OS_VER=$(/usr/bin/defaults read "$PLIST_PATH" ProductVersion)
/bin/echo "OS VERSION :" "$STR_OS_VER"
STR_MAJOR_VERSION="${STR_OS_VER%%.*}"
/bin/echo "STR_MAJOR_VERSION :" "$STR_MAJOR_VERSION"
STR_MINOR_VERSION="${STR_OS_VER#*.}"
/bin/echo "STR_MINOR_VERSION :" "$STR_MINOR_VERSION"
########################################
###ダウンロード起動時に削除する項目
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
########################################
##デバイス
#起動ディスクの名前を取得する
/bin/mkdir -p "/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID"
/usr/bin/touch "/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID/diskutil.plist"
/usr/sbin/chown -R "$CONSOLE_USER" "/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID"
/bin/chmod -Rf 700 "/Users/$CONSOLE_USER/Documents/Apple"
/usr/sbin/diskutil info -plist / >"/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID/diskutil.plist"
STARTUPDISK_NAME=$(/usr/bin/defaults read "/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID/diskutil.plist" VolumeName)
/bin/echo "ボリューム名:" "$STARTUPDISK_NAME"
############################################################
############################################################
###ユーザーbinディレクトリを作っておく
/bin/mkdir -p "/Users/$CONSOLE_USER/bin/"
for ((numTimes = 1; numTimes <= 3; numTimes++)); do
sleep 1
/bin/mkdir -p "/Users/$CONSOLE_USER/bin/"
/usr/bin/touch "/Users/$CONSOLE_USER/bin/"
/usr/sbin/chown "$CONSOLE_USER" "/Users/$CONSOLE_USER/bin/"
/bin/chmod 700 "/Users/$CONSOLE_USER/bin/"
done
# binは不可視にする
/usr/bin/chflags hidden "/Users/$CONSOLE_USER/bin"
/usr/bin/SetFile -a V "/Users/$CONSOLE_USER/bin"
###########################
###ダウンロードURL
STR_URL="https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.3.2-mac-arm64.tar.gz"
###ファイル名を取得
DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
/bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
###ダウンロード
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました"
exit 1
  fi
fi
##全ユーザー実行可能にしておく
/bin/chmod 755 "$USER_TEMP_DIR/$DL_FILE_NAME"
/bin/echo "ダウンロードOK"

############################################################
#########
/bin/echo "インストール開始:" "$CONSOLE_USER"
#コピー先を作っておく
/bin/mkdir -p "/Users/$CONSOLE_USER/bin/libwebp"
/usr/bin/touch "/Users/$CONSOLE_USER/bin/libwebp"
/usr/sbin/chown "$CONSOLE_USER" "/Users/$CONSOLE_USER/bin/libwebp"
/bin/chmod 700 "/Users/$CONSOLE_USER/bin/libwebp"
#解凍
/usr/bin/bsdtar -xzf "$USER_TEMP_DIR/$DL_FILE_NAME" -C "$USER_TEMP_DIR"
sleep 1
STR_DIRNAME=$(/usr/bin/basename -s .tar.gz "$USER_TEMP_DIR/$DL_FILE_NAME")
#コピー
/usr/bin/ditto "$USER_TEMP_DIR/$STR_DIRNAME" "/Users/$CONSOLE_USER/bin/libwebp"
#ディレクトリを開く
open "/Users/$CONSOLE_USER/bin/libwebp"
exit 0


|

[applescript]libwebpインストール


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 留意事項 インストール先が ~/bin/exiftool になっています
#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

###設定項目インストール先
set strInstrallDirPath to ("~/bin/libwebp") as text
###設定項目ダウンロードURL
set strURL to ("https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.3.2-mac-arm64.tar.gz") as text

###インストール先
set ocidInstrallDirPathStr to refMe's NSString's stringWithString:(strInstrallDirPath)
set ocidInstrallDirPath to ocidInstrallDirPathStr's stringByStandardizingPath()
set ocidInstrallDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidInstrallDirPath) isDirectory:true)
###フォルダを作る
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidInstrallDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
set strInstrallDirPath to (ocidInstrallDirPathURL's |path|()) as text


###ダウンロードURL
set ocidURLString to refMe's NSString's stringWithString:(strURL)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
set strURL to ocidURL's absoluteString() as text
set ocidFileName to ocidURL's lastPathComponent()

###ダウンロード
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 appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
##保存先ファイルURL
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName)
###ダウンロード
set ocidOption to refMe's NSDataReadingMappedAlways
set listDone to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference)
set ocidDmgData to (item 1 of listDone)
###保存
set ocidOption to refMe's NSDataWritingAtomic
set listDone to ocidDmgData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
log item 1 of listDone
set strSaveFilePath to ocidSaveFilePathURL's |path| as text

###解凍先ディレクトリを作成
set strExpandDirPathURL to (ocidSaveDirPathURL's |path|()) as text
###解凍
set strCoommandText to "/usr/bin/bsdtar -xzf \"" & strSaveFilePath & "\" -C \"" & strExpandDirPathURL & "\"" as text
do shell script strCoommandText

###ユーザーディレクトリにコピー
# moveItemAtURL:toURL:error:より上書きになるdittoを選択
set ocidTarFilePath to ocidSaveFilePathURL's URLByDeletingPathExtension()
set ocidExtractDirPath to ocidTarFilePath's URLByDeletingPathExtension()
set strExtractDirPath to ocidExtractDirPath's |path| as text
set strCoommandText to "/usr/bin/ditto \"" & strExtractDirPath & "\" \"" & strInstrallDirPath & "\"" as text
do shell script strCoommandText






|

[webpmux] アニメーションWEBPファイルから各フレームイメージを書き出す


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* libwebpが別途必要です
[applescript]libwebpインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-0a1a86.html

WEBPのアニメーションファイルからのイメージシーケンスの書き出しは
GIFと違って各フレームには
差分のみ保存されていますので あまり使いやすいものでもありません
*)
# 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 strWebpinfoPath to ("~/bin/libwebp/bin/webpinfo") as text
set strWebpmuxPath to ("~/bin/libwebp/bin/webpmux") as text


###webpinfoパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strWebpinfoPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strWebpinfoPath to ocidBinPath as string

###strWebpmuxPathパス
set ocidBinPathStr to refMe's NSString's stringWithString:(strWebpmuxPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strWebpmuxPath 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 aliasFilePath to (choose file with prompt "WEBPのアニメーションファイルを選んでください" default location aliasDesktopFolder of type {"org.webmproject.webp"} with invisibles without showing package contents and multiple selections allowed) as alias
###入力ファイル
set strFilePath to (POSIX path of aliasFilePath) as text
##出力用のディレクトリを作る
tell application "Finder"
  set strInputFileName to (name of aliasFilePath) as text
  set strSaveDirName to (strInputFileName & "_フレーム画像") as text
  set aliasContainerDirPath to (container of aliasFilePath) as alias
make new folder at aliasContainerDirPath with properties {name:strSaveDirName}
  set aliasSaveDirPath to (folder strSaveDirName of folder aliasContainerDirPath) as alias
end tell
##出力用のディレクトリのパス
set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text

############################
####webpinfo
############################
set strCommandText to ("\"" & strWebpinfoPath & "\" \"" & strFilePath & "\" | grep \"Chunk VP8L\"") as text
set strResponse to (do shell script strCommandText) as text
##フレーム数を数えます
set AppleScript's text item delimiters to "\r"
set listFlame to every text item of strResponse
set AppleScript's text item delimiters to ""
set numCntFlame to (count of listFlame) as integer
############################
####webpmux
############################
##フレームの数だけ繰り返します
repeat with itemFlameNO from 1 to numCntFlame by 1
  ##出力パス
  set strOutPutFilePath to (strSaveDirPath & itemFlameNO & ".png") as text
  ##コマンド
  set strCommandText to ("\"" & strWebpmuxPath & "\" -get frame " & itemFlameNO & " \"" & strFilePath & "\" -o \"" & strOutPutFilePath & "\"") as text
  set strResponse to (do shell script strCommandText) as text
end repeat


|

[ffmpeg]ムービーファイルをアニメーションwebpにする


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# ###FFMPEGのインストールが別途必要です
# https://ffmpeg.org/
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()
##############################
###設定項目
###FFMPEGのパス
###通常はこちらかな?
# set strBinPath to ("/usr/local/bin/ffmpeg") as text
set strBinPath to ("~/bin/ffmpeg.6/ffmpeg") as text

#ffmpeg
set ocidBinPathStr to refMe's NSString's stringWithString:(strBinPath)
set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
set strBinPath 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
############ デフォルトロケーション
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
############UTIリスト
set listUTI to {"public.movie"}

set strMes to ("ムービー・ファイルを選んでください") as text
set strPrompt to ("ムービー・ファイルを選んでください") as text
try
  ### ファイル選択時
  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
on error
log "エラーしました"
return "エラーしました"
end try

###
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:false)
set strFilePathURL to (ocidFilePathURL's |path|()) as text
set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
set strFileName to (ocidBaseFilePathURL's lastPathComponent()) as text
###AVURLAssetを利用してFPSを求める
set ocidReadAsset to (refMe's AVURLAsset's alloc()'s initWithURL:(ocidFilePathURL) options:(missing value))
set ocidReadAssetArray to (ocidReadAsset's tracksWithMediaType:(refMe's AVMediaTypeVideo))
set ocidAssetVideoTrack to (ocidReadAssetArray's objectAtIndex:0)
####フレームレートFPS
set ocidFrameRate to ocidAssetVideoTrack's nominalFrameRate()
####整数にしてテキスト化
set strFPS to ((round (ocidFrameRate * 100)) / 100) as integer


###デスクトップにファイル名のフォルダ作って
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set strSetDirName to (strFileName & "_書出") as text
set ocidSaveDirPathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strSetDirName)
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
##
set strSaveFileName to (strFileName & ".webp") as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
set strSaveFilePathURL to ocidSaveFilePathURL's |path| as text
##イメージシーケンス生成
##フル設定
# set strCommandText to ("\"" & strBinPath & "\" -i \"" & strFilePathURL & "\" -vf \"fps=" & strFPS & "\" -vcodec libwebp -loop 0 -lossless 0 -compression_level 3 -q:v 70 -preset picture -an -vsync 0 \"" & strSaveFilePathURL & "\"") as text
##簡易設定
set strCommandText to ("\"" & strBinPath & "\" -i \"" & strFilePathURL & "\" -vf \"fps=" & strFPS & "\" -vcodec libwebp -loop 0 -lossless 0 -preset photo \"" & strSaveFilePathURL & "\"") as text
do shell script strCommandText

(*


libwebp_anim AVOptions:
-lossless <int> E..V...... Use lossless mode (from 0 to 1) (default 0)
-preset <int> E..V...... Configuration preset (from -1 to 5) (default none)
none -1 E..V...... do not use a preset
default 0 E..V...... default preset
picture 1 E..V...... digital picture, like portrait, inner shot
photo 2 E..V...... outdoor photograph, with natural lighting
drawing 3 E..V...... hand or line drawing, with high-contrast details
icon 4 E..V...... small-sized colorful images
text 5 E..V...... text-like
-cr_threshold <int> E..V...... Conditional replenishment threshold (from 0 to INT_MAX) (default 0)
-cr_size <int> E..V...... Conditional replenishment block size (from 0 to 256) (default 16)
-quality <float> E..V...... Quality (from 0 to 100) (default 75)
    
*)


|

画像判定

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


set strFilePath to "/System/Library/Desktop Pictures/Big Sur Graphic.heic"

set strCommandText to "/usr/bin/xxd -p -l 2 \"" & strFilePath & "\""
set strResponse to do shell script strCommandText
if strResponse is "5249" then
  log "たぶんWEBP"
else if strResponse is "8950" then
  log "たぶんPNG"
  else if strResponse is "ffd8" then
  log "たぶんJPG"
else if strResponse is "4749" then
  log "たぶんGIF"
else if strResponse is "0000" then
  log "たぶんheic"
else
  log "不明"
end if


|

[gif2webp]GIFアニメをwebpに変換する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* 別途 gif2webpが必要です
[applescript]libwebpインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-0a1a86.html
実行してから利用してください
*)
# 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

###設定項目
set strBinPath to ("~/bin/libwebp/bin/gif2webp") as text

##バイナリのパス
set strBinPathStr to refMe's NSString's stringWithString:(strBinPath)
set ocidFilePath to strBinPathStr's stringByStandardizingPath()
set strBinPath to ocidFilePath as string
##デフォルトロケーション
tell application "Finder"
  set aliasDefaultLocation to container of (path to me) as alias
  set aliasDesktopFolder to (path to desktop folder from user domain) as alias
end tell
###ダイアログを前面に
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 listAliasFilePath to (choose file with prompt "GIFファイルを選んでください" default location aliasDefaultLocation of type {"com.compuserve.gif"} with invisibles and multiple selections allowed without showing package contents) as list

##選んだファイルの数だけ実行
repeat with itemAliasFilePath in listAliasFilePath
  tell application "Finder"
    set aliasFilePath to itemAliasFilePath as alias
    ###ファイルパスを取得
    set strFilePath to (POSIX path of aliasFilePath) as text
  end tell
  ###コマンド整形
  set strCommandText to ("\"" & strBinPath & "\" \"" & strFilePath & "\" -q 100 -o \"" & strFilePath & ".webp\"") as text
  ####実行
  tell application "Terminal"
launch
activate
    set objWindowID to (do script "\n\n")
delay 2
do script strCommandText in objWindowID
  end tell
  
  ####処理が終わるのをまってから次にかかる
  repeat
    tell application "Terminal"
      tell front window
        set boolTabStatus to busy
      end tell
    end tell
    if boolTabStatus is false then
      exit repeat
      --->このリピートを抜けて次の処理へ
    else if boolTabStatus is true then
delay 3
      --->busyなのであと3秒まつ
    end if
  end repeat
  
  
end repeat

|

[img2webp]アニメーションwebpの作成


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(* libwebpが別途必要です
[applescript]libwebpインストール
https://quicktimer.cocolog-nifty.com/icefloe/2024/01/post-0a1a86.html
*)
# 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 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




旧バージョン

#!/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
property refNSString : a reference to refMe's NSString
property refNSMutableArray : a reference to refMe's NSMutableArray

###コマ間隔 1000=1
set numDuration to 1000 as number
###出力ファイル名
set strOutPutFileName to "AnimatedWebp.webp"
###img2webpへのパス
set strCommandText to ("$HOME/bin/libwebp/bin/img2webp -loop 0 ") as text


tell application "Finder"
set aliasDefaultLocation to container of (path to me) as alias
set aliasDesktopFolder to (path to desktop folder from user domain) as alias
end tell
set strDesktopFolderPath to POSIX path of aliasDesktopFolder as text

###デスクトップに出力
set strOutPutFilePath to ("" & strDesktopFolderPath & strOutPutFileName & "") as text


####ファイル選択ダイアログ
set listChooseFile to (choose file with prompt "フォントファイルを選んでください" default location aliasDefaultLocation of type {"public.png"} with invisibles and multiple selections allowed without showing package contents) as list

###並び替え用のアレーの初期化
set ocidNewArrayM to refNSMutableArray's alloc()'s initWithCapacity:0

###選択したファイルパスをUNIXファイルパスに変換してリストに格納
repeat with objFilePath in listChooseFile
set aliasFilePath to objFilePath as alias
set strFilePath to POSIX path of aliasFilePath as text
(ocidNewArrayM's addObject:strFilePath)
end repeat

####ファイルパスを名前順に並び替え
set ocidSelf to refNSString's stringWithString:"self"
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:ocidSelf ascending:true selector:"compare:"
set ocidSortedList to (ocidNewArrayM's sortedArrayUsingDescriptors:{ocidDescriptor}) as list

####コマンド行の初期化
set strAddCommandText to ""
###ファイルパスだけ繰り返し
repeat with objFilePath in ocidSortedList
###テキストにして
set strFilePath to objFilePath 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 ("" & strCommandText & " -o \"" & strOutPutFilePath & "\"") as text

###実行
tell application "Terminal"
launch
activate
set objWindowID to (do script "\n\n")
delay 2
do script strCommandText in objWindowID
end tell

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes 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 Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray 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 NSFont AppleScript NSFontManager 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 NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange 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 NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events 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 Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV 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 SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom