# [メタ情報] # 識別子: vttからsrtを生成する兼srtの連番を付け直す_exe # システム名: vttからsrtを生成する兼srtの連番を付け直す # 技術種別: Misc # 機能名: クイックアクション # 使用言語: AppleScript # 状態: 実行用 # [/メタ情報] クイックアクション vttからsrtを生成する兼srtの連番を付け直す.worklflow ワークフローが受け取る現在の項目:ファイルまたはフォルダ AppleScriptを実行 -- 手順1 内容を複製した新たなSRTファイルを作成する。 on run {input, parameters} set srtFilePath to POSIX path of (first item of input) -- 新しいファイル名を作成 set fileName to do shell script "basename " & quoted form of srtFilePath set baseName to text 1 thru ((offset of "." in fileName) - 1) of fileName set newFileName to baseName & "_renumbered.srt" set newFilePath to (text 1 thru -((count fileName) + 1) of srtFilePath) & newFileName -- ファイルをコピーして新しいファイルを作成する do shell script "cp " & quoted form of srtFilePath & " " & quoted form of newFilePath -- 次の処理に新しいファイルのパスを渡す return {newFilePath} end run AppleScriptを実行 -- 手順2 新しいSRTファイルの内容を更新する。 on run {input, parameters} set newFilePath to POSIX path of (first item of input) -- SRTファイルの内容を読み込む set fileContent to read newFilePath as «class utf8» set fileLines to paragraphs of fileContent -- 新しい内容を生成 set newContent to "" set counter to 1 set lineCount to count of fileLines repeat with i from 1 to lineCount if (item i of fileLines) contains "-->" then -- 連番を追加 set newContent to newContent & (counter as string) & linefeed -- 時刻行 set newContent to newContent & (item i of fileLines) & linefeed -- 文章情報行 if i + 1 ≤ lineCount then set newContent to newContent & (item (i + 1) of fileLines) & linefeed end if -- 空白行 set newContent to newContent & linefeed -- 連番カウンターを増加 set counter to counter + 1 end if end repeat -- ファイルに新しい内容を書き込む set fileHandle to open for access newFilePath with write permission set eof of fileHandle to 0 write newContent to fileHandle as «class utf8» close access fileHandle return input end run