# [メタ情報] # 識別子: 字幕時刻の秒ずらしを行うworkflow_exe # システム名: 字幕時刻の秒ずらしを行う # 技術種別: Misc # 機能名: クイックアクション # 使用言語: AppleScript ShellScript # 状態: 実行用 # [/メタ情報] ワークフローが受け取る現在の項目:ファイルまたはフォルダ 検索対象:すべてのアプリケーション AppleScriptを実行 on run {input, parameters} -- 秒数を入力するダイアログを表示 display dialog "タイムシフトする秒数を入力してください:(マイナス入力も可)" default answer "0" set shiftSeconds to text returned of result -- 入力された秒数とファイルパスを返す set filePath to POSIX path of (item 1 of input) return {filePath, shiftSeconds} end run シェルスクリプトを実行 /bin/bash 入力の引き渡し方法:引数として #!/bin/bash # AppleScriptから受け取った入力 input_file="$1" shift_seconds="$2" # 元のファイルと同じディレクトリに出力ファイルを作成 output_file="${input_file%.vtt}_timeshifted.vtt" # タイムスタンプをシフトする関数 shift_timestamp() { local timestamp="$1" local shift="$2" # 時間を抽出 local hours=${timestamp:0:2} local minutes=${timestamp:3:2} local seconds=${timestamp:6:2} local milliseconds=${timestamp:9:3} # 秒数に変換 local total_seconds=$((10#$hours * 3600 + 10#$minutes * 60 + 10#$seconds + shift)) # 負の時間を扱う if [ "$total_seconds" -lt 0 ]; then total_seconds=0 fi # 時間に戻す local new_hours=$(printf "%02d" $((total_seconds / 3600))) local new_minutes=$(printf "%02d" $(((total_seconds % 3600) / 60))) local new_seconds=$(printf "%02d" $((total_seconds % 60))) echo "${new_hours}:${new_minutes}:${new_seconds}.${milliseconds}" } # ファイル処理 { while IFS= read -r line || [ -n "$line" ]; do if [[ "$line" =~ (-->) ]]; then # タイムスタンプを抽出 start_time="${line:0:12}" end_time="${line:17:12}" # タイムスタンプをシフト new_start_time=$(shift_timestamp "$start_time" "$shift_seconds") new_end_time=$(shift_timestamp "$end_time" "$shift_seconds") # 新しい行を生成 echo "${new_start_time} --> ${new_end_time}" else # タイムスタンプ行以外はそのまま出力 echo "$line" fi done } < "$input_file" > "$output_file" echo "タイムシフトされたファイルが ${output_file} に保存されました。"